gpt4 book ai didi

c# - 如何确定可为空的值类型

转载 作者:行者123 更新时间:2023-11-30 13:20:36 24 4
gpt4 key购买 nike

void Main()
{

test((int?)null);

test((bool?)null);

test((DateTime?)null);

}

void test(object p)

{

//**How to get the type of parameter p**
}

最佳答案

也许这可以帮助:

void Main()
{

test<int>(null);

test<bool>(null);

test<DateTime>(null);

}

void test<T>(Nullable<T> p)
where T : struct, new()
{
var typeOfT = typeof(T);

}

关于c# - 如何确定可为空的值类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6266783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com