gpt4 book ai didi

c# - 制作类型集合并对其进行检查的最佳方法

转载 作者:行者123 更新时间:2023-11-30 16:25:02 25 4
gpt4 key购买 nike

我如何制作一个可以存储数据类型(比如字符串、日期时间、小数等)的集合?并且使用这个集合来执行这样的比较:

if (pi.PropertyType.IsIn ([how can check against the collection of type) //where pi is a property info]))
{

}

有什么建议吗?

最佳答案

List<Type> types = new List<Type> {typeof(string), typeof(int)};
if (types.Contains(pi.PropertyType))
{
//do stuff
}

关于c# - 制作类型集合并对其进行检查的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10276146/

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