I was just working on a function that I needed to return two values, one being a column name and one being the value of that column for that current row. I am returning KeyValuePair(of String,Object). I was wondering if this is a good idea or does it make it hard to read/use?
Share
If it genuinely is a key-value pair, then that seems a pretty reasonable thing to do. .NET 4.0 will include a proper
Tupleclass for cases where there isn’t a key-value relationship.The alternative is to use out/ref parameters, letting the caller decide whether or not to keep the values together – but I prefer the
KeyValuePairapproach when there’s an obvious relationship and the caller is likely to want to keep them combined.