1

I would like to initialize a list with a given number of items, all with value DBNull.Value, is this possible via AddRange?

This code initializes as nulls and not DBNull.Value

_cellList = new List<object>(new DBNull[_columns.Count]);

Whereas this does the job correctly, but with a for loop:

_cellList = new List<object>();
for(int i = 0; i<_columns.Count; i++)
{
    _cellList.Add(DBNull.Value);
}

thanks


Create mysql view replacing a set of ints with corresponding strings

I have a mysql view where I store a set of values (hard,average,easy) as ints(3,2,1). Is there any way to create a mysql view (for my own analytics) that would replace the ints with their corresponding values?

4

1 回答 1

3

您可以Enumerable.Repeat与 结合使用ToList,如下所示:

_cellList = Enumerable
    .Repeat(DBNull.Value, _columns.Count)
    .Cast<object>()
    .ToList();

请注意使用Cast<object>(),这是构造List<object>而不是 所必需的List<DBNull>

于 2017-02-13T18:24:42.060 回答