In C# it is possible to alias classes using the following:
using Str = System.String;
Is this possible with classes that depend on generics, i have tried a similar approach but it does not seem to compile.
using IE<T> = System.Collections.Generic.IEnumerable<T>;
and
using IE = System.Collections.Generic.IEnumerable;
Is this even possible using generics in C#? If so, what is it that I am missing?
Is this possible with classes that depend on generics, i have tried a similar approach but it does not seem to compile.
using IE<T> = System.Collections.Generic.IEnumerable<T>;
No, this isn’t possible. The only thing that works is this:
using IE = System.Collections.Generic.IEnumerable<string>;
A using
declaration cannot be generic.
No, it's not possible. C# Language Specification, version 5, section 9.4.1 states:
Using aliases can name a closed constructed type, but cannot name an unbound generic type declaration without supplying type arguments. For example:
namespace N1 { class A<T> { class B {} } } namespace N2 { using W = N1.A; // Error, cannot name unbound generic type using X = N1.A.B; // Error, cannot name unbound generic type using Y = N1.A<int>; // Ok, can name closed constructed type using Z<T> = N1.A<T>; // Error, using alias cannot have type parameters }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With