c# - 术语:您如何描述 Nullable<T> 的类型 T?

标签 c# naming-conventions terminology nullable

在谈论通用类型时,Foo<T> , T被称为泛型类型的泛型参数类型参数 Foo在 .NET 中 System.Type文档。

现在,当我处理类似 int? 的类型时或 Nullable<Bar> ,在描述类型时如何引用通用参数(即我的示例中的 intBar)?

我称它为可空类型的基类型,但基类型在描述类层次结构时通常用于指代父类。 .所以我觉得在这里谈论基本类型是不对的。使用可空类型的术语通用参数让我觉得很笼统。

那么你如何谈论这些类型呢?

更具体地说,您将如何命名此扩展方法:

public static System.Type GetXxxType(this System.Type type)
{
    if ((type.IsGenericType) &&
        (type.GetGenericTypeDefinition () == typeof (System.Nullable<>)))
    {
        return type.GetGenericArguments ()[0];
    }
    else
    {
        return null;
    }
}

当通过一个 Nullable<T>此方法返回 typeof(T)结果。

最佳答案

来自规范:

A nullable type can represent all values of its underlying type plus an additional null value. A nullable type is written T?, where T is the underlying type

编辑:

引用: C# 4 规范部分 4.1.10 可空类型

关于c# - 术语:您如何描述 Nullable<T> 的类型 T?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6435025/

相关文章:

ruby - Ruby 中的标准文件命名约定

java - 在JAVA接口(interface)前放一个大写的 'I'

python - Python中导入模块后的别名变量的行话是什么?

c# - .NET Core WebAPI 依赖注入(inject)解析 null

c# - 为什么我不能使用 base.Select 在 List<string> 的子类中使用 Linq Select?

java - 命名约定 JUnit 后缀或前缀 Test

hash - 哈希值和 MAC(消息验证码)有什么区别?

c++ - 什么是 "operator int"函数?

c# - 传递给 lock 关键字的是什么?

c# - 如何清除() Entity Framework ICollection 中的所有元素?