Page 164 - CSharp/C#
P. 164

Chapter 21: Built-in Types




        Examples



        Immutable reference type - string


         // assign string from a string literal
         string s = "hello";

         // assign string from an array of characters
         char[] chars = new char[] { 'h', 'e', 'l', 'l', 'o' };
         string s = new string(chars, 0, chars.Length);

         // assign string from a char pointer, derived from a string
         string s;
         unsafe
         {
             fixed (char* charPointer = "hello")
             {
                 s = new string(charPointer);
             }
         }


        Value type - char



         // single character s
         char c = 's';

         // character s: casted from integer value
         char c = (char)115;

         // unicode character: single character s
         char c = '\u0073';

         // unicode character: smiley face
         char c = '\u263a';


        Value type - short, int, long (signed 16 bit, 32 bit, 64 bit integers)



         // assigning a signed short to its minimum value
         short s = -32768;

         // assigning a signed short to its maximum value
         short s = 32767;

         // assigning a signed int to its minimum value
         int i = -2147483648;

         // assigning a signed int to its maximum value
         int i = 2147483647;

         // assigning a signed long to its minimum value (note the long postfix)
         long l = -9223372036854775808L;



        https://riptutorial.com/                                                                             110
   159   160   161   162   163   164   165   166   167   168   169