Im trying to use the following code:
private Nullable<List<IpAddressRange>> ipAddressRangeToBind;
But I am getting the following warning:
The type List must be a non-nullable value type in order to use it as a parameter 'T' in the generic type or method 'System.Nullable'.
You can declare nullable types using Nullable<t> where T is a type. Nullable<int> i = null; A nullable type can represent the correct range of values for its underlying value type, plus an additional null value. For example, Nullable<int> can be assigned any value from -2147483648 to 2147483647, or a null value.
In C# programs, a List reference can be null. This is not the same as it being empty and having zero elements.
A list is never null. The variable might be null, but a list itself is not null.
The default value of a nullable value type represents null , that is, it's an instance whose Nullable<T>. HasValue property returns false .
List<T>
is already a reference type (for any kind of T
) - you can only declare Nullable<T>
where T
is a non-nullable value type (it's declared as Nullable<T> where T : struct
).
But that's okay, because if you just declare:
private List<IpAddressRange> ipAddressRangeToBind;
then you can still have
ipAddressRangeToBind = null;
because reference types are always nullable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With