[英]How can I create an IEnumerable list for just one item?
I have the following constructor for a class: 我有一个类的以下构造函数:
public SelectList(IEnumerable items);
I have been populating this with the following: 我一直在用以下填充:
var AccountId = new SelectList(_reference.Get("01")
.AsEnumerable()
.OrderBy(o => o.Order), "RowKey", "Value", "00");
Now I would like to populate with one element of data where the data is a list as follows: 现在,我要填充一个数据元素,其中数据是一个列表,如下所示:
RowKey = "", Value = "00"
How can I make an IEnumerable from the above line? 如何从上面的行中使IEnumerable?
Enumerable.Repeat is very convenient way to create iterators returning just one element. Enumerable.Repeat是创建仅返回一个元素的迭代器的一种非常方便的方法。 If you need iterator for 0 items use Enumerable.Empty.
如果您需要0个项目的迭代器,请使用Enumerable.Empty。
Enumerable.Repeat(new {RowKey = "", Value = "00"}, 1);
You could use an anonymous type array: 您可以使用匿名类型数组:
var AccountId = new SelectList(new[]
{
new { RowKey = "", Value = "00" }
}, "RowKey", "Value", "00");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.