Click here to Skip to main content
14,977,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
// ws is an object variable of worksheet
// systype is a string variable

Range r = (Range)ws.Cells[2, 2];
systype = r.Value2.ToString();

How can I combine these two lines into one single line?

Please help.
Updated 13-Dec-11 19:52pm

systype = ((Range)ws.Cells[2, 2]).Value2.ToString();
Wendelius 14-Dec-11 2:36am
My thought exactly, 5'd :)
Abhinav S 14-Dec-11 2:44am
Thanks Mika.
One possibility could be to just simply use parenthesis. Something like:
systype = ((Range)ws.Cells[2, 2]).Value2.ToString();

It depends on the requirements if that's a correct approach (error handling needs, if variable r is also used for something else etc).
Abhinav S 14-Dec-11 2:44am
Wendelius 14-Dec-11 2:48am
Thanks, seems that my fingers are roughly 2 minutes slower. Probably my age :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900