.net - List of KeyValuePair -


why .net not provide class list<keyvaluepair<t, u>>?

i think there lot of situations when need keep array of pairs. example,

1; 2      "a"; "array" 5; 8      "b"; "browser" 1; 9      "f"; "firefox" 8; 10     "f"; "frequency" 

À la:

pairs<int, int> mypairs;  mypairs.add(10, 8); mypairs.add(5, 8); mypairs.add(10, 5); mypairs.add(1, 4);  mypairs[0].value1 = 5; mypairs[5].value2 = 8; 

this seems unnecessary me - , because have pair of values doesn't mean it's key/value relation either.

.net 4 introduced tuple family of types... unless was key/value pair, i'd use list<tuple<t1, t2>> instead - , see no reason single type exist in order encapsulate construct.

edit: put context, here's how "difficult" use tuple here, converting sample code:

var mypairs = new list<tuple<int, int>> {     tuple.create(10, 8),     tuple.create(5, 8),     tuple.create(10, 5),     tuple.create(1, 4), }; 

now tuples immutable, wouldn't able set values directly per last part of code... beauty of composing 2 concepts of "list" , "pair of values" write own mutabletuple type , use same code... whereas if had 1 collection class hard-wired tuple or other type, wouldn't have flexibility.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -