convert int to string

M

moondaddy

How do I get the string representation of an int? for example

int var1 = 2;

string var2 = var1.ToString;

I'm wanting var2 to be "2"

I get the compile error:
Error 1 Cannot convert method group 'ToString' to non-delegate type
'string'. Did you intend to invoke the method?

Thanks.
 
M

Matt

moondaddy said:
How do I get the string representation of an int? for example

int var1 = 2;

string var2 = var1.ToString;

I'm wanting var2 to be "2"

I get the compile error:
Error 1 Cannot convert method group 'ToString' to non-delegate type
'string'. Did you intend to invoke the method?

ToString is a method, not a property.

string var2 = var1.ToString();

Matt
 
M

Michael Nemtsev

Hello moondaddy,

var1.ToString()

u can try Convert.ToString(var1)

m> How do I get the string representation of an int? for example
m>
m> int var1 = 2;
m>
m> string var2 = var1.ToString;
m>
m> I'm wanting var2 to be "2"
m>
m> I get the compile error:
m> Error 1 Cannot convert method group 'ToString' to non-delegate type
m> 'string'. Did you intend to invoke the method?
m> Thanks.
m>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
T

TerryFei

Hi Moondaddy,

We could use ToString method to achieve this goal. Just like following:
int var1 = 2;
string var2 = var1.ToString();

I hope the above information is helpful for you. Thanks and have a nice day!

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security

--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top