Could anyone tell me what is happening in this statement? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

30th Jan 2018, 7:37 AM
Yusuf
Yusuf - avatar
7 Answers
+ 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 }
30th Jan 2018, 3:24 PM
Jacob Gandemo
Jacob Gandemo - avatar
+ 3
Thank you for answer mark. But I try to understand what is happening behind this basic things. @mark
30th Jan 2018, 7:53 AM
Yusuf
Yusuf - avatar
+ 2
First of all Int32 is not a class. Secondly MaxValue is not a property. @Sujith k sukumar
30th Jan 2018, 8:46 AM
Yusuf
Yusuf - avatar
+ 2
The weird thing is that we can have a field that is a struct type in the same struct in C#.😀 @Jacob Gandemo
30th Jan 2018, 4:45 PM
Yusuf
Yusuf - avatar
+ 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.
30th Jan 2018, 4:02 PM
Jeff Faul
Jeff Faul - avatar
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"
30th Jan 2018, 7:52 AM
mark
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.
30th Jan 2018, 4:26 PM
Jacob Gandemo
Jacob Gandemo - avatar