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?
+7
A:
If it genuinely is a key-value pair, then that seems a pretty reasonable thing to do. .NET 4.0 will include a proper Tuple
class 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 KeyValuePair
approach when there's an obvious relationship and the caller is likely to want to keep them combined.
Jon Skeet
2008-11-06 12:40:49
If there is no KVP relationship then just create your own simple class encapsulating what you are returning. In the sample provided KeyValuePair seems OK.
Wolfbyte
2008-11-06 12:47:08