I am trying to create a custom list that will hold two values.
For example I have an enum:
public enum Type
{
name,
number,
surname
}
so want I want to do is have a list that will hold the enum above, Type, and a value to go with it.
For example:
List<Type type, object value>
Please assist as to how i can go about accomplishing this.
There are many ways to skin this cat.
A good option, if you only need to use this list inside a single method is to use a
List<Tuple<Type,object>>. SeeTupleon MSDN.If you do need to share the list across methods/classes, I suggest a custom type to hold both values:
And use that with
List<MyValues>.Note: Your use of
objectas a generic type is a code smell. It defeats the reasons for using generics.