Guid.NewGuid() vs. new Guid()

后端 未结 4 1069
耶瑟儿~
耶瑟儿~ 2020-12-04 06:40

What\'s the difference between Guid.NewGuid() and new Guid()?

Which one is preferred?

4条回答
  •  一个人的身影
    2020-12-04 07:02

    [I understand this is an old thread, just adding some more detail] The two answers by Mark and Jon Hanna sum up the differences, albeit it may interest some that

    Guid.NewGuid()
    

    Eventually calls CoCreateGuid (a COM call to Ole32) (reference here) and the actual work is done by UuidCreate.

    Guid.Empty is meant to be used to check if a Guid contains all zeroes. This could also be done via comparing the value of the Guid in question with new Guid()

    So, if you need a unique identifier, the answer is Guid.NewGuid()

提交回复
热议问题