Is string a primitive type??
-
Is string a primitive type or is it not? I read in Jeffrey Richter's "Applied Microsoft .NET Framework" that string (and decimal too) should be primitive types but than I tried following lines of code:
string s=""; Console.WriteLine (s.GetType().IsPrimitive.ToString());
It prints false!! Do I make something false, or does anybody have an explanation for that?? mfg -
Is string a primitive type or is it not? I read in Jeffrey Richter's "Applied Microsoft .NET Framework" that string (and decimal too) should be primitive types but than I tried following lines of code:
string s=""; Console.WriteLine (s.GetType().IsPrimitive.ToString());
It prints false!! Do I make something false, or does anybody have an explanation for that?? mfgSystem.String
is a class. AFAIK the pseudo-primitive typestring
is only a shortcut forSystem.String
. -
System.String
is a class. AFAIK the pseudo-primitive typestring
is only a shortcut forSystem.String
.Yes, I know. int is also just a shortcut for System.Int32. What I'm wondering about is, that Mr. Richter writes in his book, that string is a Primitive type and the command returns false at this method call. It also does with decimal datatype (decimal is no class), but it does not with int.
-
Yes, I know. int is also just a shortcut for System.Int32. What I'm wondering about is, that Mr. Richter writes in his book, that string is a Primitive type and the command returns false at this method call. It also does with decimal datatype (decimal is no class), but it does not with int.
hi Just go thru http://www.dotnet247.com/247reference/msgs/37/187311.aspx rgds..mil10
-
hi Just go thru http://www.dotnet247.com/247reference/msgs/37/187311.aspx rgds..mil10
Thanks!! Good explanation :cool: It says that string is no primitive type. But another question: This discussion also says that only on primitive types consts could be defined; but I am also able to define a string const with the following statement: private const string cMYCONST = "asdfjkl"; ???? :confused:
-
Thanks!! Good explanation :cool: It says that string is no primitive type. But another question: This discussion also says that only on primitive types consts could be defined; but I am also able to define a string const with the following statement: private const string cMYCONST = "asdfjkl"; ???? :confused:
As was already proven about that author, not everyone is as right as they claim to be. Whoever said that is wrong. You can declare anything as a const that can take a literal value, such as strings and other "primative" types (value types) that don't require explicit instantiation. These are your numeric types,
bool
,string
, and enums.Microsoft MVP, Visual C# My Articles
-
As was already proven about that author, not everyone is as right as they claim to be. Whoever said that is wrong. You can declare anything as a const that can take a literal value, such as strings and other "primative" types (value types) that don't require explicit instantiation. These are your numeric types,
bool
,string
, and enums.Microsoft MVP, Visual C# My Articles
Thanks for the answer. I think I understand now a little more about those value/reference types... Heath Stewart wrote: As was already proven about that author, not everyone is as right as they claim to be. Whoever said that is wrong. What do you mean with it, does Jeffrey Richter have more mistakes in his articels than it seem to be there??
-
Thanks for the answer. I think I understand now a little more about those value/reference types... Heath Stewart wrote: As was already proven about that author, not everyone is as right as they claim to be. Whoever said that is wrong. What do you mean with it, does Jeffrey Richter have more mistakes in his articels than it seem to be there??
Actually, I was referring to the comment in the discussion someone linked that said that only "primatives" could be declared as consts. The fact that Jeffrey Richter said that
String
was a primative (and I'm taking your word for it) would be incorrect, yes. The Framework supports that by what you saw (which, BTW, you don't need to useBoolean.ToString
inConsole.WriteLine
, since it formats every argument - regardless of type - as a string anyway; see my article, Custom String Formatting in .NET[^] for a brief discussion, though the article's not about that so much).Microsoft MVP, Visual C# My Articles
-
Is string a primitive type or is it not? I read in Jeffrey Richter's "Applied Microsoft .NET Framework" that string (and decimal too) should be primitive types but than I tried following lines of code:
string s=""; Console.WriteLine (s.GetType().IsPrimitive.ToString());
It prints false!! Do I make something false, or does anybody have an explanation for that?? mfgI would say string is primitive as it is directly supported in the CLR. Decimal on the hand, is not. top secret
-
I would say string is primitive as it is directly supported in the CLR. Decimal on the hand, is not. top secret
Hi all... I just back to my machine today morning after Easter vacation. Have gone thru all comments. Frankly, as of now, I don't have that much in depth idea about it to say something authentically. Thanks very much for all valuable inputs so that I can consider those to identify the truth. rgds...mil10.