Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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
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?
您可以Enumerable.Repeat与 结合使用ToList,如下所示:
Enumerable.Repeat
ToList
_cellList = Enumerable .Repeat(DBNull.Value, _columns.Count) .Cast<object>() .ToList();
请注意使用Cast<object>(),这是构造List<object>而不是 所必需的List<DBNull>。
Cast<object>()
List<object>
List<DBNull>