码迷,mamicode.com
首页 > 其他好文 > 详细

Nullable不是泛型类, 但方法可以是泛型的;

时间:2020-03-02 09:14:50      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:泛型   The   其它   summary   false   null   als   object   which   

注意where限制,防止用户输入struct或其它primitive类型

    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;
    }
}

Nullable不是泛型类, 但方法可以是泛型的;

标签:泛型   The   其它   summary   false   null   als   object   which   

原文地址:https://www.cnblogs.com/onecrazystone/p/12393250.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!