How does C# generate GUIDs?

后端 未结 8 1266
北荒
北荒 2020-12-17 07:38

How are GUIDs generated in C#?

8条回答
  •  清酒与你
    2020-12-17 08:29

    A Guid is a unique number that has billions of permutations and is made up of a mixture of hexadecimal and numbers in groups. And it is generated based on the different factors, such as time, windows version, system resources such as hard disks, motherboards, devices and so on. A Guid is guaranteed to be unique. (Thanks ck!) I have not seen an instance where you do

    Guid g = new Guid.NewGuid();
    Guid g = Guid.NewGuid(); /* Thanks Dave! */
    

    where g will have the same value in successive runs.

    It is more commonly used for mutexes, an example would be to create a single instance of an application and by using a mutex with a guid guarantees the lifetime of the instance of the application.

    Even, in some instances, it is used in the database but the method of using it is frowned upon.

提交回复
热议问题