C # introduction and use of GUID,

Source: Internet
Author: User

C # introduction and use of GUID,

GUID (globally unified identifier) refers to the number generated on a machine, which ensures that all machines in the same time and space are unique. Generally, the platform provides APIs for generating guids. The generation algorithm is very interesting. It uses Ethernet Card addresses, nanoseconds, chip ID codes, and many possible numbers. The unique defect of GUID is that the generated result string is large.

GUID is always convenient. For all aspects of program development,. NET Framework simplifies the process of establishing and processing the GUID value. Where the. NET program needs it, this function can easily generate a unique value.

 

1. a guid is a 128-bit integer (16 bytes). When using a unique identifier, you can use this integer between all computers and networks.

2. The GUID format is "xxxxxxxx-xxxx-xxxxxxxxxxxx", where each x is a hexadecimal number in the range of 0-9 or a-f. For example, 337c7f2b-7a34-4f50-9141-bab9e6478cc8 is a valid GUID value.

3. No duplicate GUID value is generated on any two computers in the world (Koffer Note: it should be on the Earth. GUID is used to assign a unique identifier to a network or system with multiple nodes and computers.

4. On Windows, GUID is widely used: Registry, class and interface identification, database, or even automatically generated machine name and directory name.

Use GUID in. NET

GUID is widely used in. NET, and. NET Framework provides a dedicated Guid infrastructure.

Common Guid structure methods include:
1) Guid. NewGUID () generates a new GUID unique value
2) Guid. ToString () converts the GUID value to a string for processing
3) constructor Guid (string)
The Guid structure is generated by the string, where the string can be in upper or lower case. It can contain the delimiters "{}" or "()" at both ends. you can even omit the "-" in the middle. There are many constructors in the Guid structure, and other constructors are not commonly used.

In. NET Framework, you can use the GuidConverter class to provide a type converter that converts the Guid structure with various other representations.

 

Generate a GUID in C # to process a unique identifier, making it easier to store and obtain information. This function is particularly useful when processing a database because a GUID can operate on a primary key. Similarly, SQL Server well integrates the usage of GUID. The SQL Server Data Type uniqueidentifier can store a GUID value. You can use the NEWID () function to generate this value in SQL Server, or you can generate a GUID outside SQL Server, and then manually insert this value.

In. NET, the latter method is more direct .. The basic System class in the. NET Framework includes the GUID value type. In addition, this value type contains the method for processing the GUID value. Specifically, the NewGUID method allows you to easily generate a new GUID.

 

In. NET, the GUID format is as follows:

1. Guid. NewGuid (). ToString ("N"): 38bddf48f43c48588e0d78761eaa1ce6

2. The result of Guid. NewGuid (). ToString ("D") is 57d99d89-caab-482a-a0e9-a0a803eed3ba (the default value is 2nd effects)

3. Guid. NewGuid (). ToString ("B"): {09f140d5-af72-44ba-a763-c861304b46f8}

4. Guid. NewGuid (). ToString ("P"): (778406c2-efff-4402-ab03-70a77d09c2b5)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.