Is it possible to return KeyValuePair from a .NET function?

I was just working on a function in which I needed to return two values, one of which is the name of the column, and the other is the value of this column for this current row. I am returning KeyValuePair (from String, Object). I was wondering if this is a good idea or is it difficult to read / use?

+4
source share
1 answer

If this is really a key-value pair, then that seems pretty reasonable..NET 4.0 will include the correct Tuple class for cases where key-value relationships are missing.

An alternative is to use the out / ref parameters, which allow the caller to decide whether to keep the values ​​together, but I prefer the KeyValuePair approach when the obvious relationship and the caller are most likely to want to keep them together.

+7
source

All Articles