0

Is it possible to create generic type definition using using in C#?

For example, I would want to do the following:

namespace MyNamespace
{
  using TPred<T> = Expression<Func<T, bool>>;

  public class Predicates
  {
    public static TPred<T> False<T> => f => false;

    public static TPred<T> True<T> => f => true;

    public static TPred<T> Or<T> (this TPred<T> expr1, TPred<T> expr2)
    {
      ...
    }
  }
}

I believe that it is not possible, but wanted to verify it with wise folks from Stack Overflow ;).

Jarek
  • 74
  • 4
  • 2
    A `using` directive never creates a new type, generic or not. If you're actually asking if you can use *aliases* with generic types, that's a different matter... but I don't *think* there's such a thing as a generic alias. – Jon Skeet Sep 05 '16 at 15:52
  • Posting answer to avoid people jumping between sites as the other question is more involved. It is not possible. Further, parametrizing alias is not allowed as well, e.g. `Expr = Expression;` wouldn't allow to specify the following type `Expr>`. In short, don't mix aliasing with generics. – Jarek Sep 05 '16 at 16:44

0 Answers0