Search code examples
c#typedef

Cannot define a type shortcut using "using"


I am trying to define a shortcut to a type that I use a lot in my code:

using IntPair = ValueTuple<int, int>;

I get an error:

The type or namespace "ValueTuple" could not be found.

But, I can use ValueTuple in the rest of my code with no problem.

Is this the correct way to define the type shortcut?


Solution

  • As detailed in the using directives specifications:

    the namespace_or_type_name of a using_alias_directive is resolved as if the immediately containing compilation unit or namespace body had no using_directives.

    Which means that you should fully qualify the type you're aliasing:

    using IntPair = System.ValueTuple<int, int>;