开发者

Alias ​​for class with many typeparams in other class body (C#)

开发者 https://www.devze.com 2023-02-19 01:09 出处:网络
I declare a class with many typeparams: public class A<T1, T2, T3, T4, T5> {} How can I use alias like this:

I declare a class with many typeparams:

public class A<T1, T2, T3, T4, T5> {}

How can I use alias like this:

public class B<T1, T2, T3, T4, T5>
{
开发者_JAVA技巧    using T = A<T1, T2, T3, T4, T5>

    public void Method()
    {
        T.StaticMethod();
    }
}


You can do this with the rest of your using statements:

using MyList = System.Collections.Generic.Dictionary<int, string>;

Then you can use the class like so:

MyList x = new MyList();
x.Add(0, "Hello World");

However, this is kinda bad design. In the example you posted, B still had 5 generic type arguments, so nothing much is gained.

0

精彩评论

暂无评论...
验证码 换一张
取 消