如何从对象获取值 [英] How to get values from object
本文介绍了如何从对象获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有empid列表存储在var变量c#中.我想从该变量中获取值.我该怎么做.
例如:
Hi all,
I have list of empid stored in var variable c#. i want to get the values from that variable. how i can do this.
eg:
var empid=viewstate["empid"];
现在,该empid包含三个empemp,如emp1,emp2,emp3.我该如何检索此var变量中存在的每个值.
有人可以举例说明吗?
谢谢
parithi
now the empid contains three empid like emp1,emp2,emp3 how can i retrieve each values that present in this var variable.
can anybody explain with example
Thanks
parithi
推荐答案
看看是否有帮助,
See if this helps,
List<double> d = new List<double>();
d.Add(1);
d.Add(2);
d.Add(3);
d.Add(4);
var v = d;
List<double> newVal = (List<double>)v;
就像这样:
like this:
var empid = viewstate["empid"];
foreach(int employeeID in (List<int>)empid)
{
Console.WriteLine(employeeID);
}
检查此
首先,您必须Cast
您的ViewState
Hi ,
Check this
First you have toCast
yourViewState
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<string> st = new List<string>();
st.Add("me");
st.Add("mm");
st.Add("ee");
st.Add("rr");
ViewState.Add("st", st);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (ViewState["st"] != null)
{
List<string> stView = (List<string>)ViewState["st"];
foreach (string item in stView)
{
TextBox1.Text += item;
}
}
}
最好的问候
米特瓦里(M.Mitwalli)
Best Regards
M.Mitwalli
这篇关于如何从对象获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文