How to set null to a GUID property

后端 未结 8 1924
春和景丽
春和景丽 2020-12-16 10:25

I have an object of type Employee which has a Guid property. I know if I want to set to null I must to define my type property as nullable Nullable

8条回答
  •  臣服心动
    2020-12-16 10:44

    you can make guid variable to accept null first using ? operator then you use Guid.Empty or typecast it to null using (Guid?)null;

    eg:

     Guid? id = Guid.Empty;
    

    or

     Guid? id =  (Guid?)null;
    

提交回复
热议问题