Click here to Skip to main content
15,878,871 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
How can I create a 2 dimensional list?first of all I thank every one who answered me and then As answered, I can have one list in another one, but then how can I reach the elements easily?In fact I want to have something like this:"a[i,j]" and reach the elements around "a[i,j]" and then have the maximum,average,... of them. as you know I can easily reach the maximum by using lists.If there is no way do so,Is there any method in C# that can help me have the maximum,average,... thanks again
Posted
Updated 28-Jun-11 22:11pm
v2

Try List<List<object>> objects;. Obviously object could be any CLR type.

Hope this helps
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Jun-11 4:04am    
Correct, my 5.

My 2 cents:
I decided to write 5 lines of real code which would compile immediately as I think OP may have a little problem writing it, assuming little experience.

Please see my answer.
--SA
ambarishtv 29-Jun-11 4:08am    
My +5
BobJanova 29-Jun-11 4:49am    
For the OP's reference: to index into a list of lists:
item = listoflists[i][j];
To make a correct answer by Wayne a bit more clear:

C#
using ListOfList =
    System.Collections.Generic.List<
        System.Collections.Generic.List<ListItem>
    >;

class ListItem = {/*...*/}
//or any other type


—SA
 
Share this answer
 
Comments
ambarishtv 29-Jun-11 4:09am    
My 5 :thumbsup:
Sergey Alexandrovich Kryukov 29-Jun-11 4:11am    
Thank you.
--SA
this link will help you
http://www.dotnetperls.com/nested-list[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Jun-11 4:06am    
Sorry, I think this link show not so good code sample. Hard-coded "3" everywhere, why?...
Please see my answer and the one by Wayne.
--SA

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