Guid类型的变量不会为空,初始化没有赋值的GUID应该是00000000-0000-0000-0000-000000000000 。

正确的判断应该是if(Guid testId== Guid.Empty)

如:

  Guid guid = Guid.Parse("00000000-0000-0000-0000-000000000000"); 
            //Guid guid = Guid.Parse("E441C253-5080-4619-803A-00849D8CF710");
            Console.WriteLine(guid);
            if (guid == Guid.Empty)
            {
                Console.WriteLine("GUID无效");
            }
            else
            {
                Console.WriteLine("GUID有效");
            }

            Console.Read();

 

输出结果为:

guid是否为空的判断

 但是Guid?  guid = null  是可以的为空的, 判断方式:

      Guid? guid = null;
     if (guid.ToString() == "" || !guid.HasValue)
            {
                Console.WriteLine("GUID无效");
            }

 

相关文章:

  • 2021-06-11
  • 2021-09-23
  • 2021-06-08
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-11-27
  • 2021-11-28
  • 2021-11-28
  • 2021-07-04
相关资源
相似解决方案