Guid.NewGuid() vs. new Guid()

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

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

Which one is preferred?

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 07:07

    Guid.NewGuid(), as it creates GUIDs as intended.

    Guid.NewGuid() creates an empty Guid object, initializes it by calling CoCreateGuid and returns the object.

    new Guid() merely creates an empty GUID (all zeros, I think).

    I guess they had to make the constructor public as Guid is a struct.

提交回复
热议问题