Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Is string a primitive type??

Is string a primitive type??

Scheduled Pinned Locked Moved C#
csharpdotnetquestion
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    Ungi
    wrote on last edited by
    #1

    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

    C L 2 Replies Last reply
    0
    • U Ungi

      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

      C Offline
      C Offline
      Corinna John
      wrote on last edited by
      #2

      System.String is a class. AFAIK the pseudo-primitive type string is only a shortcut for System.String.

      U 1 Reply Last reply
      0
      • C Corinna John

        System.String is a class. AFAIK the pseudo-primitive type string is only a shortcut for System.String.

        U Offline
        U Offline
        Ungi
        wrote on last edited by
        #3

        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.

        M 1 Reply Last reply
        0
        • U Ungi

          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.

          M Offline
          M Offline
          Milton Karimbekallil
          wrote on last edited by
          #4

          hi Just go thru http://www.dotnet247.com/247reference/msgs/37/187311.aspx rgds..mil10

          U 1 Reply Last reply
          0
          • M Milton Karimbekallil

            hi Just go thru http://www.dotnet247.com/247reference/msgs/37/187311.aspx rgds..mil10

            U Offline
            U Offline
            Ungi
            wrote on last edited by
            #5

            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:

            H 1 Reply Last reply
            0
            • U Ungi

              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:

              H Offline
              H Offline
              Heath Stewart
              wrote on last edited by
              #6

              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

              U 1 Reply Last reply
              0
              • H Heath Stewart

                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

                U Offline
                U Offline
                Ungi
                wrote on last edited by
                #7

                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??

                H 1 Reply Last reply
                0
                • U Ungi

                  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??

                  H Offline
                  H Offline
                  Heath Stewart
                  wrote on last edited by
                  #8

                  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 use Boolean.ToString in Console.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

                  1 Reply Last reply
                  0
                  • U Ungi

                    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

                    L Offline
                    L Offline
                    leppie
                    wrote on last edited by
                    #9

                    I would say string is primitive as it is directly supported in the CLR. Decimal on the hand, is not. top secret

                    M 1 Reply Last reply
                    0
                    • L leppie

                      I would say string is primitive as it is directly supported in the CLR. Decimal on the hand, is not. top secret

                      M Offline
                      M Offline
                      Milton Karimbekallil
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups