Answers for "nullable guid to guid c#"

C#
0

nullable guid to guid c#

Use the ?? operator:

public static class Extension
{
   public static Guid ToGuid(this Guid? source)
   {
       return source ?? Guid.Empty;
   }

   // more general implementation 
   public static T ValueOrDefault<T>(this Nullable<T> source) where T : struct
   {
       return source ?? default(T);
   }
}
Posted by: Guest on June-21-2021

C# Answers by Framework

Browse Popular Code Answers by Language