How can I do the following in C#? What is the right way to write the first line of this code snippet?
using KVP<K, V> = System.Collections.Generic.KeyValuePair<K, V>;
class C { KVP<int, string> x; }
How can I do the following in C#? What is the right way to write the first line of this code snippet?
using KVP<K, V> = System.Collections.Generic.KeyValuePair<K, V>;
class C { KVP<int, string> x; }
You can't, basically. You can only use fixed aliases, such as:
using Foo = System.Collections.Generic.KeyValuePair<int, string>;
class C { Foo x; }
In some cases you can go with inheritance:
public class MyList<T1, T2> : List<Tuple<IEnumerable<HashSet<T1>>, IComparable<T2>>> { }
public void Meth()
{
var x = new MyList<int, bool>();
}
Though not in your particular case, as KeyValuePair is sealed :-(