NULL可能ではない一般的なクラスは、それが一般的な方法であってもよいです。

制限は、ユーザー入力またはその他のプリミティブ型を防ぐことに注意してください構造体

    public class Nullable
    {
        public Nullable();

        //
        // Summary:
        //     Creates an empty NullableRef<T> object which HasValue property is false.
        public static NullableRef<T> Create<T>() where T : class;
        //
        // Summary:
        //     Creates a non-empty NullableRef<T> object that holds reference to the given object
        //     t.
        public static NullableRef<T> Create<T>(T t) where T : class;
        //
        // Summary:
        //     Creates an empty SafeNullableRef<T> object which HasValue property is false.
        public static SafeNullableRef<T> CreateSafe<T>() where T : class, IDisposable;
        //
        // Summary:
        //     Creates a non-empty SafeNullableRef<T> object that holds reference to the given
        //     object t, and that takes responsibility for disposing the t object.
        public static SafeNullableRef<T> CreateSafe<T>(T t) where T : class, IDisposable;
    }
}

おすすめ

転載: www.cnblogs.com/onecrazystone/p/12393250.html