How to use string as variable name in c#

后端 未结 2 541
孤街浪徒
孤街浪徒 2020-12-22 13:02

am having a viewstate which pertains value like:

string temp; ViewState[\"temp\"] = dc.ColumnName.ToString();

This returns weekdays like:

2条回答
  •  [愿得一人]
    2020-12-22 13:07

    You can not declare objects at runtime they way you art trying. You can store the week days in array / List starting Monday at index 0 and Sunday at index 6, You can give id of element with the string name you want.

    List weekList = new List();
    weekList.Add(new TextBox());
    weekList[0].ID  =  "txt" + ViewState["temp"].ToString();
    

提交回复
热议问题