0

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?

4

2 に答える 2

3

Enumerable.Repeat is very convenient way to create iterators returning just one element. If you need iterator for 0 items use Enumerable.Empty.

Enumerable.Repeat(new {RowKey = "", Value = "00"}, 1);
于 2012-05-03T02:07:47.523 に答える
2

You could use an anonymous type array:

var AccountId = new SelectList(new[] 
                { 
                    new { RowKey = "", Value = "00" }
                }, "RowKey", "Value", "00");
于 2012-05-03T02:00:29.893 に答える