gpt4 book ai didi

c# - 如何与 System.Type 进行比较?

转载 作者:太空狗 更新时间:2023-10-29 23:56:15 26 4
gpt4 key购买 nike

DataSet.Tables[0].Columns[0] 中,我们有一个 DataType 属性。现在,我想遍历 Columns 并根据 DataType 中的 Type 执行一些操作。如何做到这一点?

foreach(var c in DataSet.Tables[0].Columns)
{
if (c.DataType == System.String) {} //error 'string' is a 'type', which is not valid in the given context

}

最佳答案

使用 typeof运算符(operator):

if (c.DataType == typeof(string))
{
// ...
}

关于c# - 如何与 System.Type 进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3299917/

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