DEV Community

Discussion on: C# value type variables and reference type variables (Question)

Collapse
 
selftuaght profile image
SelfTuaght • Edited

Hey man, thanks for the input but can you link any web sources that support the following statement you made: "Literals are similar, when you type "Richard" you are telling the compiler to instance a String type object with the given content and 24 is telling the compiler to instance a Int32 object with the value of twenty-four."

Is there any C# Microsoft documentation that supports such argument?

Collapse
 
jayjeckel profile image
Jay Jeckel

No, I can't think of a link that directly says this. It is kind of assumed that one would understand that a string literal is a string object. If you need proof, as I said in my post, Console.WriteLine("Richard".GetType()); will show that a string literal is of the type System.String and Console.WriteLine(24.GetType()); will show a integer literal is of type System.Int32.

If you have to have a link, I guess the Strings page of the C# Programming Guide implies it by showing a string variable being initialized with a string literal:

// Initialize with a regular string literal.
string oldPath = "c:\\Program Files\\Microsoft Visual Studio 8.0";
Enter fullscreen mode Exit fullscreen mode

Likewise, the Integral Numeric Types page of the C# reference makes it about as clear as can be that numeric literals are of the Int32 type unless they have a literal suffix that declares them as another type.

int a = 123;
System.Int32 b = 123;
Enter fullscreen mode Exit fullscreen mode