插入到int值相同的所有列中

本文关键字:int 插入 | 更新日期: 2023-09-27 17:57:36

在LINQ中,如何在表1中所有int类型的列中插入相同的数值:1,而不使用数字(colint1、colint2、colint3、colint4)指定每一列?

插入到int值相同的所有列中

您可以对对象'o'和新整数值'newValue'使用类似的反射(对不起,我在这台机器上没有VS来测试它):

foreach(PropertyInfo prop in o.GetType().GetProperties()) 
{
    if(prop.PropertyType == typeof(int))
        prop.SetValue(o, newValue, null);
}

然后只需确保保存您的更改