hi all im new to c# and ned a bit of help i want a list containing pairs of string not uniqe for example
mylist.add("bob", "steve");
mylist.add("bob", "ben");
mylist.add("ben", "steve");
and would contain
mylist[0] bob steve
mylist[1] bob ben
mylist[2] ben steve
how would i do this in code thanks.
Loading
Sam HobbsPosted Jul 11, 2010, 1:42 AM
I do not understand the question, though; would the above work? If not and you still need help then please explain.
theLizardPosted Jul 10, 2010, 5:49 PM
public class namepairs
{
public string a, b;
public namepairs(string first, string second)
{
a = first; b = second;
}
}
List
myList.Add(new namepairs("bob", "steve"));
myList.Add(new namepairs("bob", "ben"));
myList.Add(new namepairs("ben", "steve"));
Roy SPosted Jul 10, 2010, 4:15 PM
http://www.c-sharpcorner.com/UploadFile/mahesh/2002/
Or maybe you could just add the first and last name together, separated by a space and store that in a list?
dave hicksPosted Jul 10, 2010, 3:57 PM
dave hicksPosted Jul 10, 2010, 3:55 PM
Ajay GautamPosted Jul 10, 2010, 3:50 PM
Please find the example, hope it helps you. Just understand the logic of List because it list can save only 1 value at a time.
Laurentiu PopoviciPosted Jul 10, 2010, 3:41 PM
http://blog.dynamicprogrammer.com/2009/05/25/TupleANewTypeOnNet40.aspx
Otherwise, you can use List
>.
List
> myList = new List
>(); listTwoStrings = new List(2);
List
listTwoStrings.Add("Bob");
listTwoStrings.Add("Steve");
myList.Add(listTwoStrings);