Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
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();


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

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900