Is Guid considered a value type or reference type?

前端 未结 6 1298
-上瘾入骨i
-上瘾入骨i 2021-01-03 18:32

Guids are created using the new keyword which makes me think it\'s a reference type.

Is this correct?

Guid uid = new Guid();

<
6条回答
  •  囚心锁ツ
    2021-01-03 19:01

    Its value type, See the below example:

    using System;                   
    public class Program
    {
        public static void Main()
        {
            Guid a1 = new Guid();
            Console.WriteLine(a1);
            Guid b1 = a1;
            Console.WriteLine(b1);
            a1 = Guid.NewGuid();
            Console.WriteLine(a1);
            Console.WriteLine(b1);
        }
    }
    
    /* OUTPUT
    00000000-0000-0000-0000-000000000000
    00000000-0000-0000-0000-000000000000
    164f599e-d42d-4d97-b390-387e8a80a328
    00000000-0000-0000-0000-000000000000
    */
    

提交回复
热议问题