Click here to Skip to main content
15,903,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
For some reason I can't think of anything today, I have been programming for a while and should know the answer to this.

For some reason I remember using a List<string,string,string>

Or a some kind of list that uses more than one argument.

Please help me.
Posted

Hello

Try this:
C#
public class MyClass
{
    public MyClass(params object[] objs)
    {
       foreach(object o in objs)
       {
            //Some UnBoxing Code...
       }
    }
}

And:
C#
List<MyClass> myList = new List<MyClass>();

myList.Add(new MyClass(12,"",DateTime.Now));
 
Share this answer
 
v4
A list can contain only one object at an index (though that object can be a list or a complex object, as in Mika's answer). One suggestion I have is

C#
List<Tuple<string,string,string>> Foo = new List<Tuple<string,string,string>>();
//Then you'd add:
Foo.Add(Tuple.Create"("Bar","Baz","Quux"));
//Or
Foo.Add(new Tuple<string,string,string>("Bar","Bax", "Quux");


Obviously this is less readable them Mika's suggestion, and it relies on the developer to get the order of the strings right each time. It does, however, fit your description better (but not 100%), so perhaps this is what you were thinking of.



One further suggestion (though it doesn't really match what you say) is a "3d list" (i.e. a list of a list of a list of strings):
C#
List<List<List<string>>>

But again the first list contains a single item at each index, which just happens to be another List.

Finally, the code you saw could be an implementation of a generic class which wrappers up the type work up that are described in the various answers you've had so far. If this is the case, I'd have to question what MySpecialGenericList[0] would mean, as it tecnically stores three strings, all of which are required to form the item, but only one can be returned without resorting to a tuple or complex object. Either of these return types are not the original thing passed in, so this would, in my view, be symantically incorrect.
 
Share this answer
 
v2
It depends, what are you're requirements. If you need to store several string to a list, one possibility is to create a class to hold the values and place instances of that class to the list. Something like
C#
public class DataHolder {
   public string Text1 { get; set; }
   public string Text2 { get; set; }
   public string Text3 { get; set; }
}

...

public List<DataHolder> DataList = new public List<DataHolder>();

...

DataList.Add(new DataHolder() { Text1 = "A", Text2 = "B" };

If you need a dictionary based list then you can use Dictionary<tkey,>[^]
 
Share this answer
 
Comments
ZaiDz 27-May-12 3:59am    
It works just like that would but it's used like List<string> but with more arguments
This is an example

I might just be making this up but I remember using it.

Classname = just an example since I have no clue what it's called


ClassName<string,string,int,int> cn = new ClassName<string,string,int,int>();


void AddItem()
{
cn.Add("string1","string2",23,555);
}
Wendelius 27-May-12 4:17am    
That sounds more like a generic class. Have a look at http://msdn.microsoft.com/en-us/library/sz6zd40f(v=vs.100).aspx[^]
ZaiDz 27-May-12 4:20am    
I have no clue, maybe it doesn't exist...
ZaiDz 27-May-12 4:21am    
It wasn't something that I need for a project I just thought of it and now I just really want to know

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900