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:
C#
// 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

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.
One possibility could be to just simply use parenthesis. Something like:
C#
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900