Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generic NOT constraint where T : !IEnumerable

As per the title, is it possible to declare type-negating constraints in c# 4 ?

like image 224
Cel Avatar asked Jan 04 '12 13:01

Cel


People also ask

Where is generic type constraint?

The where clause in a generic definition specifies constraints on the types that are used as arguments for type parameters in a generic type, method, delegate, or local function. Constraints can specify interfaces, base classes, or require a generic type to be a reference, value, or unmanaged type.

What is T type in C#?

T is called type parameter, which can be used as a type of fields, properties, method parameters, return types, and delegates in the DataStore class. For example, Data is generic property because we have used a type parameter T as its type instead of the specific data type. Note.

Which of the following generic constraints restricts the generic type parameter to an object of the class?

Value type constraint If we declare the generic class using the following code then we will get a compile-time error if we try to substitute a reference type for the type parameter.


1 Answers

No - there's no such concept either in C# or in the CLR.

like image 198
Jon Skeet Avatar answered Sep 23 '22 02:09

Jon Skeet