{"id":91660,"date":"2023-06-17T08:00:07","date_gmt":"2023-06-17T06:00:07","guid":{"rendered":"https:\/\/code-maze.com\/?p=91660"},"modified":"2023-11-08T15:15:42","modified_gmt":"2023-11-08T14:15:42","slug":"csharp-guid-class","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-guid-class\/","title":{"rendered":"Working With Guid in C#"},"content":{"rendered":"<p>In the world of software development, maintaining data integrity and uniqueness is of utmost importance. One such unique identifier in C# is the Guid (Globally Unique Identifier) class. In this article, we will explore the Guid class in .NET, its features, and how we can implement it in our applications.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/csharp-classes-struct-record\/GuidClassInCSharp\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s start exploring!<\/p>\n<h2>What Is a Guid?<\/h2>\n<p><strong>A Guid is a 128-bit value that possesses an exceedingly low probability of duplication.<\/strong> It is represented by a sequence of characters in the form <code>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx<\/code>.<\/p>\n<p><strong>Guid values are unique because they consist of 32 hexadecimal digits<\/strong>, resulting in an enormous number of possible combinations (approximately 3.4 * 10^38), making the likelihood of generating the same Guid practically impossible.<\/p>\n<h2>Usage of Guid in C#<\/h2>\n<p>The usage of Guid holds significant advantages in software development. We employ Guids when there is a need for absolute uniqueness and identification across various systems and applications. They serve as ideal choices for primary keys in databases, ensuring data integrity and avoiding conflicts during data merging.<\/p>\n<p>However, a challenge we may face when using Guids as keys is the issue of fragmentation. The randomness of GUIDs can cause data to be scattered across various locations, impacting performance and making it less efficient for operations like indexing and searching.<\/p>\n<p>Also, Guids are valuable in <strong>distributed systems<\/strong>, where we need to identify and track multiple entities uniquely. Their capability to generate unique identifiers on different devices and platforms makes them indispensable for scenarios such as message queues, data replication, and multi-tenant systems.<\/p>\n<p>Furthermore, we use Guids extensively for <strong>user identification<\/strong>, <strong>filename generation<\/strong>, <strong>cryptography<\/strong>, and maintaining <strong>integrity<\/strong> in complex systems.<\/p>\n<p><strong>The wide range of applications and the guarantee of uniqueness make the <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.guid?view=net-7.0\" target=\"_blank\" rel=\"nofollow noopener\">Guid<\/a> class a crucial component in modern software development.<\/strong><\/p>\n<h2>How Do We Create a Guid in C#?<\/h2>\n<p>To explore the <code>Guid<\/code> class and its capabilities, let&#8217;s start by creating a console application project in Visual Studio. To do this, we either use the Project Wizard or type in the command window <code>dotnet new console<\/code>.<\/p>\n<p>Let&#8217;s create our first random <code>Guid<\/code>:\u00a0<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var randomGuid = Guid.NewGuid();\r\nConsole.WriteLine(randomGuid); \/\/ 5671c043-84d5-4da6-9863-c1a5710fca58\r\n<\/pre>\n<p>We have a new instance of the <code>Guid<\/code> class object by using the <code>NewGuid()<\/code> method. It is stored in the variable <code>randomGuid<\/code> and then we print the output to the console window.<\/p>\n<p>We observe that the <code>NewGuid()<\/code> method creates a <a href=\"https:\/\/code-maze.com\/csharp-structures\/\" target=\"_blank\" rel=\"noopener\">struct<\/a> with a unique identifier value. This is a static method of the <code>Guid<\/code> class that produces a different outcome every time.\u00a0<\/p>\n<p>It should be noted here that the GUIDs generated by .NET, specifically using <a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc4122#section-4.4\" target=\"_blank\" rel=\"nofollow noopener\">UUID v4<\/a>, are entirely random. This randomness can potentially lead to collisions when multiple workers within the same distributed system solely rely on the <code>Guid.NewGuid()<\/code> method for GUID generation. To address these concerns, we can introduce a dedicated mechanism in the distributed system that all workers adhere to for GUID generation.<\/p>\n<p><strong>Another way we can create a random Guid value is directly from the Visual Studio IDE.<\/strong> From the top bar menu, we click <em>Tools -&gt;Create GUID<\/em>. In the next form, we choose the <em>&#8216;Guid Format&#8217;<\/em> we desire, and we get a new value each time we click\u00a0 &#8216;<em>New GUID&#8217;<\/em>.<\/p>\n<h3>Create a Guid With Specific Value<\/h3>\n<p>In .NET, many times we need to create a <code>Guid<\/code> object with a specific value:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var specificGuid = new Guid(\"3F2504E0-4F89-11D3-9A0C-0305E82C3301\");<\/code><\/p>\n<p>Here, we use the constructor of the <code>Guid<\/code> class that parses a given <code>string<\/code> and creates a <code>Guid<\/code> object based on the provided value. The result is the expected hexadecimal sequence.<\/p>\n<p>The <code>string<\/code> value must be a valid representation of a Guid, meaning it should consist of 32 hexadecimal digits, grouped into five sections separated by hyphens. The case of the hexadecimal letters (A-F) in the string representation is not significant.<\/p>\n<p>Moreover, if we pass a <code>string<\/code> value to the constructor that is not a valid Guid representation, an exception of type <code>FormatException<\/code> is thrown.<\/p>\n<p>If we want to avoid this, we can use the <a href=\"https:\/\/code-maze.com\/csharp-parse-tryparse\/\" target=\"_blank\" rel=\"noopener\">TryParse()<\/a> method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public Guid TryParseGuid(string inputStringGuid)\r\n{\r\n    if (Guid.TryParse(inputStringGuid, out Guid outputGuid))\r\n    {\r\n        return outputGuid;\r\n    }\r\n    else\r\n    {\r\n        \/\/handle non valid guid format.\r\n        return Guid.Empty;\r\n    }\r\n}<\/pre>\n<p>The <code>TryParse()<\/code> method takes a <code>string<\/code> as an input argument. If the <code>string<\/code> is in a valid Guid format, it stores its value in the out variable and returns true. Otherwise, it returns false.<\/p>\n<div style=\"padding: 20px; border-left: 5px gray solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To learn more about the out keyword, check out our great article <a href=\"https:\/\/code-maze.com\/cshrap-ref-out-keywords\/\" target=\"_blank\" rel=\"noopener\">Difference Between Ref and Out Keywords in C#<\/a>.<\/div>\n<h3>Create an Empty Guid in C#<\/h3>\n<p>An empty Guid is a special value of the <code>Guid<\/code> class in C#. It is a pre-defined instance that represents a &#8220;zero&#8221; or &#8220;empty&#8221; Guid, which is the default value for Guid instances when we do not assign a specific Guid:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var emptyGuid = new Guid();\r\nConsole.WriteLine(emptyGuid); \/\/ 00000000-0000-0000-0000-000000000000<\/pre>\n<p>Here, we observe that the <code>emptyGuid<\/code> variable has all of its bytes set to zero.<\/p>\n<p>Moreover, we can get the same result if we set the variable <code>emptyGuid<\/code> equal to the <code>Guid.Empty<\/code> value:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var emptyGuid = Guid.Empty; \/\/ 00000000-0000-0000-0000-000000000000<\/code><\/p>\n<p>Finally, we can see that the result is the same sequence of zeros. The empty Guid serves as a convenient default value for <code>Guid<\/code> instances and allows us to easily detect uninitialized or empty <code>Guid<\/code> instances in our code.<\/p>\n<h2>Guid Methods in C#<\/h2>\n<p>Now, we will delve into common methods and extensions available in the <code>Guid<\/code> class, unlocking the full potential of this essential component in C# development. By understanding these methods and extensions, we will have a comprehensive understanding of how to manipulate and work with Guids effectively in our C# applications.<\/p>\n<h3>The ToString() Method<\/h3>\n<p>The <a href=\"https:\/\/code-maze.com\/tostring-method-csharp\/\" target=\"_blank\" rel=\"noopener\">ToString()<\/a> method converts the <code>Guid<\/code> object to a <code>string<\/code> representation:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public string GuidToString(Guid inputGuid)\r\n{\r\n    return inputGuid.ToString();\r\n}<\/pre>\n<p>This implementation uses the &#8220;D&#8221; format by default. In addition, we can specify different <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.guid.tostring?view=net-7.0#system-guid-tostring(system-string):~:text=Remarks-,The%20following%20table%20shows%20the%20accepted%20format%20specifiers%20for%20the%20format%20parameter.%20%220%22%20represents%20a%20digit%3B%20hyphens%20(%22%2D%22)%2C%20braces%20(%22%7B%22%2C%20%22%7D%22)%2C%20and%20parentheses%20(%22(%22%2C%20%22)%22)%20appear%20as%20shown.,-Specifier\" target=\"_blank\" rel=\"nofollow noopener\">formats<\/a>, such as &#8220;N&#8221;, &#8220;B&#8221;, or &#8220;P&#8221;, using the <code>Guid.ToString(string format)<\/code> overload:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var inputGuid = Guid.NewGuid();\r\n\r\nvar guidStringD = inputGuid.ToString(\"D\"); \/\/ f5060e47-6b59-4de6-aa2e-1f5e307e4d01\r\n\r\nvar guidStringN = inputGuid.ToString(\"N\"); \/\/ f5060e476b594de6aa2e1f5e307e4d01\r\n\r\nvar guidStringB = inputGuid.ToString(\"B\"); \/\/ {f5060e47-6b59-4de6-aa2e-1f5e307e4d01}\r\n\r\nvar guidStringP = inputGuid.ToString(\"P\"); \/\/ (f5060e47-6b59-4de6-aa2e-1f5e307e4d01)<\/pre>\n<p>Here, we use the accepted format specifiers for the <code>format<\/code> parameter. The hyphens <code>-<\/code>, braces <code>{}<\/code>, and parentheses <code>()<\/code> appear as shown in each case.<\/p>\n<h3>Equality and Comparison Methods<\/h3>\n<p>We can compare <code>Guid<\/code> instances by using the <code>Equals()<\/code> method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var guidA = new Guid(\"BE116B09-81D5-40F2-9A06-89E14066DFA6\");\r\nvar guidB = new Guid(\"097D07C5-6897-4240-B9DE-D6179DCF6B6F\");\r\nvar equalGuids = guidA.Equals(guidB); \r\n\r\nConsole.WriteLine(equalGuids) \/\/ false<\/pre>\n<p>Here, we construct two different <code>Guid<\/code> instances and compare them using the <code>Equals()<\/code> method. This method returns a <code>boolean<\/code> value, and in this case, it returns false.\u00a0<\/p>\n<p>The same can be performed using the equality operators <code>==<\/code> and <code>!=<\/code>. <strong>However, since <code>Guid<\/code> is a struct value type, equality operators and the <code>Equals()<\/code> method always have the same results. <\/strong>They compare the underlying bytes of the <code>Guid<\/code> to determine equality.<\/p>\n<p>Let&#8217;s compare two <code>Guid<\/code> instances with the non-equal operator:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var nonEmptyGuid = new Guid(\"BE116B09-81D5-40F2-9A06-89E14066DFA6\");\r\nvar equalGuids = nonEmptyGuid != Guid.Empty;\r\n\r\nConsole.WriteLine(equalGuids); \/\/ true<\/pre>\n<p>This check might be useful in cases where we want to see if a <code>Guid<\/code> does not have a value assigned.<\/p>\n<h3>The ToByteArray() Method<\/h3>\n<p>As we know, a Guid value consists of 16 bytes, each representing 8 bits, which collectively make up the 128 bits. The <code>ToByteArray()<\/code> method in the <code>Guid<\/code> struct returns a byte array representation of this value.<\/p>\n<p>Let&#8217;s convert a <code>Guid<\/code> to a <code>byte[]<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var inputGuid = Guid.NewGuid();\r\nvar byteArray = inputGuid.ToByteArray();\r\n\r\nConsole.WriteLine(BitConverter.ToString(byteArray)); \/\/ 31-A7-5A-C8-0C-24-D5-46-98-A8-ED-98-84-97-F8-03<\/pre>\n<p>First, we create a new <code>Guid<\/code> and we store its bytes in the <code>byteArray<\/code> variable. Then, we use the <code>BitConverter.ToString()<\/code> method to convert the byte array to a <code>string<\/code> representation for display.<\/p>\n<p>The output is a string that represents the Guid value in its binary form, where each byte corresponds to two characters in the output string, and the bytes are separated by dashes (&#8220;-&#8220;).<\/p>\n<p>The <code>ToByteArray()<\/code> method is useful in scenarios where we need to work with the <code>Guid<\/code> value at a lower level. These cases might be storing it in a database column that accepts binary data or performing custom byte-level operations on the <code>Guid<\/code>.<\/p>\n<p>Similarly, we can make up a <code>Guid<\/code> with specific byte values using its constructor that takes as argument a byte array:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var byteArray = new byte[16] { 0xA1, 0x5F, 0x03, 0xC8, 0x23, 0x7B, \r\n0x42, 0x5C, 0xB3, 0xFF, 0x7D, 0xCB, 0x1C, 0x4A, 0x92, 0x00 };\r\nvar guidFromBytes = new Guid(byteArray);<\/pre>\n<div class=\"group w-full text-gray-800 dark:text-gray-100 border-b border-black\/10 dark:border-gray-900\/50 bg-gray-50 dark:bg-[#444654]\">\n<div class=\"flex p-4 gap-4 text-base md:gap-6 md:max-w-2xl lg:max-w-xl xl:max-w-3xl md:py-6 lg:px-0 m-auto\">\n<div class=\"relative flex w-[calc(100%-50px)] flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]\">\n<div class=\"flex flex-grow flex-col gap-3\">\n<div class=\"min-h-[20px] flex flex-col items-start gap-4 whitespace-pre-wrap break-words\">\n<div class=\"markdown prose w-full break-words dark:prose-invert dark\">\n<p>Here, we have a <code>byte[]<\/code> that represents the 16 bytes of a <code>Guid<\/code> value. The constructor <code>Guid(byte[])<\/code> takes the byte array as a parameter and creates a new <code>Guid<\/code> instance using the provided bytes.<\/p>\n<p><strong>It&#8217;s important to note that<\/strong> <strong>the byte array must be exactly 16 bytes long, as a Guid is a 128-bit value represented by 16 bytes. Otherwise, if the byte array doesn&#8217;t have exactly 16 elements, or if it is null, an exception will be thrown.<\/strong><\/p>\n<p>Constructing a Guid from a byte array can be useful when we want to reassemble a Guid from its individual byte components. For example, we may retrieve the bytes from a database or other storage medium and want to reconstruct the <code>Guid<\/code> object from its low-level form.<\/p>\n<h3>The TryWriteBytes() Method<\/h3>\n<p>A similar way to convert a Guid to byte format is with the usage of the <code>TryWriteBytes()<\/code> method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var inputGuid = Guid.NewGuid();\r\nSpan&lt;byte&gt; dest = stackalloc byte[16];\r\ninputGuid.TryWriteBytes(dest);\r\n\r\nConsole.WriteLine(BitConverter.ToString(dest.ToArray())); \/\/ 41-13-43-31-C1-14-C0-4C-AD-08-7E-A6-31-57-4C-18<\/pre>\n<p>First, we allocate a <code>Span&lt;byte&gt;<\/code> <code>dest<\/code> using <code>stackalloc byte[16]<\/code>. This reserves memory on the stack for 16 bytes, which we will use to store the byte representation of the new <code>Guid<\/code>.<\/p>\n<p>Next, we call the <code>TryWriteBytes<\/code> method on the <code>inputGuid<\/code> to write the byte representation of the <code>Guid<\/code> into the <code>dest<\/code> span, which attempts to write the bytes of the <code>Guid<\/code> into the provided span, returning <code>true<\/code> if the write operation is successful.<\/p>\n<p>Finally, we convert the byte span\u00a0to an array using <code>dest.ToArray()<\/code>method, and then we use <code>BitConverter.ToString()<\/code> method to convert the byte array into a string representation. This results in a string with the hexadecimal values of the bytes separated by hyphens, as previously.<\/p>\n<p>This code performs better in contrast to the <code>ToByteArray()<\/code> method solution, as stack allocation is generally faster than heap allocation. It involves a simple pointer adjustment rather than going through the heap memory management process.<\/p>\n<p>We write the byte representation of the <code>Guid<\/code> directly into the stack-allocated span using <code>TryWriteBytes()<\/code>method. This avoids an additional memory copy operation that is required with the <code>ToByteArray()<\/code>, which creates a new byte array on the heap and copies the bytes from the <code>Guid<\/code> into it.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h2>Conclusion<\/h2>\n<p>In this article, we explored the Guid class and its functionalities in C#. Furthermore, we examined different ways to create Guids. This included generating random Guids, constructing Guids from specific values or byte arrays, and working with common methods. With its extensive functionality, the Guid class empowers developers to implement robust identification and data integrity mechanisms in their C# applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the world of software development, maintaining data integrity and uniqueness is of utmost importance. One such unique identifier in C# is the Guid (Globally Unique Identifier) class. In this article, we will explore the Guid class in .NET, its features, and how we can implement it in our applications. Let&#8217;s start exploring! What Is [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62189,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12],"tags":[1811,1838],"class_list":["post-91660","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","tag-c","tag-guid","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Working With Guid in C# - Code Maze<\/title>\n<meta name=\"description\" content=\"In this article, we explore the Guid class in C#, looking at how we create them, and working with some of the methods provided for us.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/csharp-guid-class\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Working With Guid in C# - Code Maze\" \/>\n<meta property=\"og:description\" content=\"In this article, we explore the Guid class in C#, looking at how we create them, and working with some of the methods provided for us.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-guid-class\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-17T06:00:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-08T14:15:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Code Maze\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Code Maze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/csharp-guid-class\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-guid-class\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"Working With Guid in C#\",\"datePublished\":\"2023-06-17T06:00:07+00:00\",\"dateModified\":\"2023-11-08T14:15:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-guid-class\/\"},\"wordCount\":1566,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-guid-class\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\"C#\",\"guid\"],\"articleSection\":[\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-guid-class\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-guid-class\/\",\"url\":\"https:\/\/code-maze.com\/csharp-guid-class\/\",\"name\":\"Working With Guid in C# - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-guid-class\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-guid-class\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2023-06-17T06:00:07+00:00\",\"dateModified\":\"2023-11-08T14:15:42+00:00\",\"description\":\"In this article, we explore the Guid class in C#, looking at how we create them, and working with some of the methods provided for us.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-guid-class\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-guid-class\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-guid-class\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/csharp-guid-class\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Working With Guid in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\",\"name\":\"Code Maze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"caption\":\"Code Maze\"},\"description\":\"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/codemaze\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/codemazecontributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Working With Guid in C# - Code Maze","description":"In this article, we explore the Guid class in C#, looking at how we create them, and working with some of the methods provided for us.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/csharp-guid-class\/","og_locale":"en_US","og_type":"article","og_title":"Working With Guid in C# - Code Maze","og_description":"In this article, we explore the Guid class in C#, looking at how we create them, and working with some of the methods provided for us.","og_url":"https:\/\/code-maze.com\/csharp-guid-class\/","og_site_name":"Code Maze","article_published_time":"2023-06-17T06:00:07+00:00","article_modified_time":"2023-11-08T14:15:42+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","type":"image\/png"}],"author":"Code Maze","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Code Maze","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-guid-class\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-guid-class\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"Working With Guid in C#","datePublished":"2023-06-17T06:00:07+00:00","dateModified":"2023-11-08T14:15:42+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-guid-class\/"},"wordCount":1566,"commentCount":1,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-guid-class\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":["C#","guid"],"articleSection":["C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-guid-class\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-guid-class\/","url":"https:\/\/code-maze.com\/csharp-guid-class\/","name":"Working With Guid in C# - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-guid-class\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-guid-class\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2023-06-17T06:00:07+00:00","dateModified":"2023-11-08T14:15:42+00:00","description":"In this article, we explore the Guid class in C#, looking at how we create them, and working with some of the methods provided for us.","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-guid-class\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-guid-class\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-guid-class\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","width":1100,"height":620,"caption":"C# Development"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/csharp-guid-class\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Working With Guid in C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04","name":"Code Maze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","caption":"Code Maze"},"description":"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.","sameAs":["https:\/\/www.linkedin.com\/company\/codemaze\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/codemazecontributor\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/91660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=91660"}],"version-history":[{"count":7,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/91660\/revisions"}],"predecessor-version":[{"id":96520,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/91660\/revisions\/96520"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62189"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=91660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=91660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=91660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}