Click here to Skip to main content
15,072,134 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
mcard_list mcardlist = new mcard_list();
numberoftimes = 0;
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.


      case "DateTime" :

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


   numberoftimes += 1;

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

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.

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