如何在C#中为generics类创build别名?

我如何在C#中执行以下操作? 写这段代码的第一行的正确方法是什么?

using KVP<K, V> = System.Collections.Generic.KeyValuePair<K, V>; class C { KVP<int, string> x; } 

你基本上不能。 您只能使用固定的别名,例如:

 using Foo = System.Collections.Generic.KeyValuePair<int, string>; class C { Foo x; } 

在某些情况下,你可以inheritance:

 public class MyList<T1, T2> : List<Tuple<IEnumerable<HashSet<T1>>, IComparable<T2>>> { } public void Meth() { var x = new MyList<int, bool>(); } 

虽然不是在你的具体情况,因为KeyValuePair被封:-(