使用点替换实体表替换局部变量的问题 [英] Problem on attach local variable with entity table substitute with dot

查看:57
本文介绍了使用点替换实体表替换局部变量的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mcard_list mcardlist = new mcard_list();
numberoftimes = 0;
timesheet.AddTomcard_list(mcardlist);
while (numberoftimes < collectionnumbers)
{
    var FieldName = mcardlistfields[numberoftimes, 0].ToString();
    var FieldType = mcardlistfields[numberoftimes, 1].ToString();

   switch (FieldType)
  {

      case "String" :


         mcardlist. + FieldName = "Test"; <=I know wrong here but i don't know how to do.

         break;

      case "DateTime" :

         mcardlist. + FieldName = "2015-1-23"; <=I know wrong here I don't know how to do it.

         break;
  }

   numberoftimes += 1;
}
timesheet.SaveChanges();







Could Anyone help me how can add fieldname stored in variable "FieldName" for later attach with "mcardlist." (ended with dot).Thanks.

推荐答案

你不能去做。你不能从变量的内容中创建一个变量名。



我不知道这个用途是什么,但有一个想法是转换 mcardlist 到一组键/值对中。 I Dictionary集合就是其中的一个例子。
You cannot do that. You cannot make a variable name from the contents of a variable.

I have no idea what this is used for, but one idea would be to convert mcardlist into a collection of Key/Value pairs. I Dictionary collection would be one example of that.


这篇关于使用点替换实体表替换局部变量的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆