【发布时间】:2019-06-25 13:35:45
【问题描述】:
List<Dictionary<string, object>> data = new List<Dictionary<string, object>>();
Dictionary<string, Object> objs = new Dictionary<string, object>();
for (int i = 1; i <= onlineolanlar.Count; i++)
{
objs.Add(i.ToString(), new userLevel() { UserID = userID.ToString(), Presence = UserLevelBul.ToString() });
}
foreach (var item5 in objs.Values)
{
//How can I access item5 properties here??
}
大家好,
我怎样才能达到那个 foreach 循环的值?
item5 应该有属性 userid 和 userlevelbul 但我无法访问它们。
【问题讨论】:
-
尽可能详细地解释这一点:
in item5 there are userid and userlevelbul but i cant reach them -
使用
UserID, Presence, etc..创建一个类型并将该类型添加到objs,而不是添加匿名类型。 -
当我写 item5.它只显示 equals.gethashcode 等。没有用户 ID...
-
声明你的字典
objs为Dictionary<string, userLevel>, -
很少有合法地需要直接使用
Object类型的情况。 99% 的情况下,您希望使用更具体的类型 (userLevel)。
标签: c# asp.net dictionary