Click here to Skip to main content
14,331,729 members
Rate this:
Please Sign up or sign in to vote.
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.
Posted
Updated 13-Dec-11 19:52pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

Try
systype = ((Range)ws.Cells[2, 2]).Value2.ToString();
   
Comments
Wendelius 14-Dec-11 2:36am
   
My thought exactly, 5'd :)
Abhinav S 14-Dec-11 2:44am
   
Thanks Mika.
Rate this:
Please Sign up or sign in to vote.

Solution 2

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).
   
Comments
Abhinav S 14-Dec-11 2:44am
   
5!
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100