110,534
社区成员
发帖
与我相关
我的任务
分享
//stcTmp 是个结构体
public struct stc1
{
public string sTable;
public string sColumn;
public stcColumn(int n)
{
sTable = "";
sColumn = "";
}
}
stc1 stcTmp =new stc1(0);
foreach (FieldInfo fiTmp in stcTmp.GetType().GetFields())
{
if (fiTmp != null)
{
fiTmp.SetValue(stcTmp, "aaa");
}
}
这句 fiTmp.SetValue(stcTmp, "aaa")无效,请问各位高手哪里错了?
stc1 stcTmp = new stc1(0);
object o = stcTmp;
foreach (FieldInfo fiTmp in stcTmp.GetType().GetFields())
{
if (fiTmp != null)
{
fiTmp.SetValue(o, "aaa");
}
}
stcTmp = (stc1)o;
Console.WriteLine(stcTmp.sColumn);