M
M
Maxim2016-07-17 20:47:46
C++ / C#
Maxim, 2016-07-17 20:47:46

Convert.ToString or var.ToString. What is the difference?

What's the difference between

int var;

string str = Convert.ToString(var);
string str2 = var.ToString();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2016-07-17
@Got_Oxidus

Specifically for int and specifically this envelope overload - nothing.
https://msdn.microsoft.com/ru-ru/library/x70d7t0y(...
And so - Convert is used when you need to specify additional formatting features.

D
Dmitry Nesterov, 2016-07-22
@Guo

well, initially you better not call the var variable (if it worked for you at all), var is used to declare a variable. Well, so that 2 times long names do not write or choose (if there are many names of the same name).
var a = new MyReleaseMethod(); let's say something like this, where MyRelizMetod is your method (which you yourself wrote).
using ToString() you can only convert to a string, using the Convert.* package you can convert types between each other, so let's get a number from the terms (it is important that the string contains only numbers). Or convert the value of a variable of type double to a variable of type decimal

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question