如何在Ienumerable(动态)中迭代 [英] How to Iterate in Ienumerable (dynamic)
问题描述
我有一个IEnumerable值的列表,我想迭代并得到每个值。我将无法明确说出迭代中的值。
Hi,
I have a List of IEnumerable values which i would like to iterate and get each and every values.I will not be able to explicitly say the values in the iteration.
var lst = IEnumerable列表
var lst = list of IEnumerable
foreach(lst中的动态项目)
{
//迭代其中的所有字段,不能明确提及字段名称。
foreach (dynamic item in lst)
{
// iterate all the fields inside this, cant mention the field name explicitly.
//不想访问字段这个 (例如,var data = item.fieldname1)
// Don't want to access field lik this (eg. var data = item.fieldname1)
}
推荐答案
我有一个IEnumerable值列表,我会喜欢迭代并获取每个值。我将无法明确说出迭代中的值。
Hi,
I have a List of IEnumerable values which i would like to iterate and get each and every values.I will not be able to explicitly say the values in the iteration.
var lst = IEnumerable列表
var lst = list of IEnumerable
foreach(lst中的动态项目)
{
//迭代其中的所有字段,不能明确提及字段名称。
foreach (dynamic item in lst)
{
// iterate all the fields inside this, cant mention the field name explicitly.
//不想访问字段这个 (例如,var data = item.fieldname1)
// Don't want to access field lik this (eg. var data = item.fieldname1)
}
https://social.msdn.microsoft.com/Forums/en-US/3894982b-9670-4e24-8748-0e4e339a038a/ef-dynamic-type-the-sqlparameter-is-已经包含了另一个-sqlparametercollection?forum = adodotnetentityframework
https://social.msdn.microsoft.com/Forums/en-US/3894982b-9670-4e24-8748-0e4e339a038a/ef-dynamic-type-the-sqlparameter-is-already-contained-by-another-sqlparametercollection?forum=adodotnetentityframework
我在上面的链接中给出了答案,即使用后期绑定。你不是在使用动态定义的对象,因为动态相当于使用Object,它是.NET中使用的所有对象
的基本定义对象。
I gave you the answer in the link above, which is to use late binding. You are not coming around it in using an object that has been defined using dynamic, becuase dynamic is the equivalent of using Object that is the base definition object for all objects used in .NET.
这篇关于如何在Ienumerable(动态)中迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!