+ 2
Could anyone tell me what is happening in this statement?
Int32.MaxValue.ToString() I looked the definition of ToString(), the ToString() method used with an instance of Object class. And Object class is a base class for all class(I am telling what I understand). But I don't know how they used Int32 without instantiating him. Could you tell me?
7 Réponses
+ 3
The reason you can use the ToString() method on Int32.MaxValue is because it is already initiated in the Int32 struct (almost the same as a class) as a constant value.
public struct Int32
{
public const Int32 MaxValue = 2147483647;
public const Int32 MinValue = -2147483648;
//+Many more methods
}
+ 3
Thank you for answer mark. But I try to understand what is happening behind this basic things. @mark
+ 2
First of all Int32 is not a class.
Secondly MaxValue is not a property.
@Sujith k sukumar
+ 2
The weird thing is that we can have a field that is a struct type in the same struct in C#.😀 @Jacob Gandemo
+ 1
I'm new to C# but it looks like the Int32 is an array of numbers as Jacob mentioned then you have MaxValue which looks like it is searching toint32 for the "MaxValue" and then converting it to a string with .ToString.
It looks like part of the code is missing to completely understand what is going on. but I defer to Jacob's response.
0
i am not sure I understand the question exactly. That said I will try to answer it anyways.
ToString() in most languages would be used to change output from another type to string.
Example:
z = 2 + 2; // Resulting in the interger 4
z = ToString( 2 + 2); // Resulting is the string "4"
0
@Jeff Fail
Don't worry, but this question has nothing to do with an array of numbers.
Int32 is an 32 bit Integer and the MaxValue call gets you the biggest possible number for a this Integer which is the number 2147483647.
And this code is already defined in the c# library or the .Net Framework as it is called.