Is it possible to exclude certain types from the set of possible types that can be used in a common parameter? If so, how.
for example
Foo<T>() : where T != bool
will mean any type except bool type.
Edit
Why?
The following code is my attempt to enforce a negative constraint.
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var x1=Lifted.Lift("A"); var x2=Lifted.Lift(true); } static class Lifted {
As you can see, this is due to some belief in the correct resolution of the overload and the @jonskeet -esque evil code bit.
Comment on the suggestion section of the proposed type and it doesn't work.
It would be much better to have an excluded general restriction.
Adam speech
source share