Alex Rivera | Logout

Multiple parameters in a List. How to create without a class?

Asked 2010-11-23T21:29:52.453
70

This is probably a pretty obvious question, but how would I go about creating a List that has multiple parameters without creating a class.

Example:

var list = new List<string, int>();

list.Add("hello", 1);

I normally would use a class like so:

public class MyClass
{
    public String myString {get; set;}
    public Int32 myInt32 {get; set;}
}

then create my list by doing:

var list = new List<MyClass>();
list.Add(new MyClass { myString = "hello", myInt32 = 1 });
Edit
Report

1 Answer

5

List only accepts one type parameter. The closest you'll get with List is:

 var list = new List<Tuple<string, int>>();
 list.Add(Tuple.Create("hello", 1));
answered 2010-11-23T21:34:15.667

Your Answer