需要为List中的每个项创建新实例 [英] Need to create new instance for every item in List

查看:71
本文介绍了需要为List中的每个项创建新实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含对象的List。我需要在for循环中将值设置为此对象

I have a List containing objects. I need to set the value as this object in a for loop

foreach(fieldvalueentries中的FieldValueEntry fv1)

{

foreach (FieldValueEntry fv1 in fieldvalueentries)
{

filterSelection.FieldValues = new [] {fv1};

filterSelection.FieldValues = new[] { fv1 };

}

 通过这样做,我知道只会分配列表中的最后一个值。但我想动态创建FieldValues并将其分配给filterSelection。

 By doing this I know only the last value in the list will be assigned. But I want to dynamically create FieldValues and assign it to filterSelection.

请帮忙吗?

推荐答案

您没有提供任何类型信息,因此我们不会有太大用处。你有多个filterSelection实例吗?它是一个数组吗?

You didn't provide any type information so we aren't going to be of much use. Do you have multiple filterSelection instances? Is it an array?

如果您尝试将FieldValues设置为fieldvalueentries列表,那么就这样做。

If you're trying to set FieldValues to the list of fieldvalueentries then just do this.

//Assuming fieldvalueentries is of type IEnumerable<T> 
filterSelection.FieldValues = fieldvalueentries.ToArray();


这篇关于需要为List中的每个项创建新实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆