Answered by:
Declare Nested List or List<List<>>

Question
-
User-574293449 posted
hi,
I have a applciation which cotains a List<byte>. This is collection of single data. Now i need different set of these data. So i need to declare List<List<byte> .
The outer list have fixed number of lists inside. Kindly guid or give alternative if i am wrong
Wednesday, August 21, 2013 7:31 AM
Answers
-
User1109032460 posted
Absolutely, yes.
Just read the value from the configuration setting and replace the hardcoded value (10) that I used in my little sample.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, August 21, 2013 9:03 AM -
User-573138384 posted
But why you told List<List<byte>> is complex. Anyway i need check the index for a particlar set of List<byte> so even if i use dictioanry i need check the index in the key . Am i right? or any advatage for using dictionaryReadability is one observation when I do code review. In future if someone wants to maintain the code you write, they should easily understand. If you use nested level, it might be a little difficult to understand. BTW, I persoanlly used Dictionary a lot. I rememeber few advantages too.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, August 21, 2013 9:06 AM
All replies
-
User-573138384 posted
Technically nothing wrong but why do you want to use List<List<byte>>? It will make your code complex. Can you use Dictionary and have some key to uniquely identify the inner List<byte> and work on this Dictionary?
List<byte> obj1 = new List<byte>(); List<byte> obj2 = new List<byte>(); Dictionary<string, List<byte>> abc = new Dictionary<string, List<byte>>(); abc.Add("id1", obj1); abc.Add("id2", obj2);
Wednesday, August 21, 2013 8:24 AM -
User-574293449 posted
good method. But why you told List<List<byte>> is complex. Anyway i need check the index for a particlar set of List<byte> so even if i use dictioanry i need check the index in the key . Am i right? or any advatage for using dictionary
Wednesday, August 21, 2013 8:57 AM -
User1109032460 posted
If the outer List is fixed in size, simply use an array, so
List<byte>[] lists = new List<byte>[10];
Remember that allocating the array will not allocate the individual lists within the array.
Wednesday, August 21, 2013 8:58 AM -
User-574293449 posted
yes this i want. Actually my outer List count is based on the value from config. So anyway i can create this fixed value based on the config key in the load event itself
Wednesday, August 21, 2013 9:02 AM -
User1109032460 posted
Absolutely, yes.
Just read the value from the configuration setting and replace the hardcoded value (10) that I used in my little sample.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, August 21, 2013 9:03 AM -
User-573138384 posted
But why you told List<List<byte>> is complex. Anyway i need check the index for a particlar set of List<byte> so even if i use dictioanry i need check the index in the key . Am i right? or any advatage for using dictionaryReadability is one observation when I do code review. In future if someone wants to maintain the code you write, they should easily understand. If you use nested level, it might be a little difficult to understand. BTW, I persoanlly used Dictionary a lot. I rememeber few advantages too.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, August 21, 2013 9:06 AM -
User-574293449 posted
Thanks . I got it. As the outer List is fixed based on config value i used the option like DMW told
Wednesday, August 21, 2013 9:08 AM