No, there is no such syntax in C#.
From MSDN:
The following table lists the six types of constraints:
where T: struct The type argument must be a value type.
Any value type except Nullable can be specified. See Using Nullable
Types for more information. where T : class The type argument must be
a reference type; this applies also to any class, interface, delegate,
or array type.
where T : new() The type argument must have a public
parameterless constructor. When used together with other constraints,
the new() constraint must be specified last.
where T : (base class name) The type argument must be or derive from the specified base
class.
where T : (interface name) The type argument must be or
implement the specified interface. Multiple interface constraints can
be specified. The constraining interface can also be generic.
where T : U The type argument supplied for T must be or derive from the
argument supplied for U.
So there is no option to say where T is any type other than U
Think about it this way - suppose you had
class myClass<T> where T: !string
{
}
You know T
is not a string, but you have no other indication of what T
might be. So how do you code against it? These would all be valid delcarations:
var x1 = new myClass<int>();
var x2 = new myClass<object>();
var x3 = new myClass<DateTime>();
var x4 = new myClass<DataTable>();
What code could you have that applies to all of these types, but would be invalid for string
?