.NET Fiddle

CSharp · Console

/Program.cs

using System;
using System.Diagnostics.CodeAnalysis;

public static class Utils
{
  [return: NotNullIfNotNull(nameof(dt))]
  public static DateTime? ToUtc(DateTime? dt) => dt?.Kind switch
  {
    null => null,
    _ => ToUtc(dt)
  };
	
  public static DateTime ToUtc(DateTime dt) => dt.Kind switch
  {
    DateTimeKind.Unspecified => DateTime.SpecifyKind(dt, DateTimeKind.Utc),
    DateTimeKind.Utc => dt,
    DateTimeKind.Local => dt.ToUniversalTime()
  };
}

class Example {
  public static void Ex1() 
  {
    DateTime? dt0 = DateTime.Now;
    DateTime? dt1 = Utils.ToUtc(dt0); // all is ok
  }

  public static void Ex2() 
  {
    DateTime dt0 = DateTime.Now;
    DateTime dt1 = Utils.ToUtc(dt0); // error here: Cannot implicity convert type 'System.DateTime?' to 'System.DateTime'...
  }
}
;