没问题.
至少BCL就经常这么干,不信你试一下: List<string> l = new List<string>(-100);
using System.Collections.Generic;
using System;
class P
{
static void Main()
{
var l = new List<string>(-100);
Console.WriteLine(l.Count);
}
}
public List(int capacity) {
if (capacity < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.capacity, ExceptionResource.ArgumentOutOfRange_SmallCapacity);
_items = new T[capacity];
}
List.cs的代码