ExtensionMethod.NET Home of 877 C#, Visual Basic, F# and Javascript extension methods

String to Guid

This is used to be common in web api's. When you must to receive the guid as a string in parameter.


public static Guid ToGuid(this string value)
    Guid.TryParse(value, out Guid result);
    return result;


string value = "cf3d75d2-59b6-4d22-b74a-daa9d3dadd64";

Console.WriteLine(value); // output: cf3d75d2-59b6-4d22-b74a-daa9d3dadd64

Author: meiro

Submitted on: 24 jul. 2023

Language: csharp

Type: System.Guid

Views: 1327