Last post Aug 21, 2013 09:08 AM by akhilrajau
Aug 21, 2013 07:31 AM|akhilrajau|LINK
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
Aug 21, 2013 08:24 AM|fayaz_3e|LINK
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>>();
Aug 21, 2013 08:57 AM|akhilrajau|LINK
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
Aug 21, 2013 08:58 AM|DMW|LINK
If the outer List is fixed in size, simply use an array, so
List<byte> lists = new List<byte>;
Remember that allocating the array will not allocate the individual lists within the array.
Aug 21, 2013 09:02 AM|akhilrajau|LINK
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
Aug 21, 2013 09:03 AM|DMW|LINK
Just read the value from the configuration setting and replace the hardcoded value (10) that I used in my little sample.
Aug 21, 2013 09:06 AM|fayaz_3e|LINK
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
Readability 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.
Aug 21, 2013 09:08 AM|akhilrajau|LINK
Thanks . I got it. As the outer List is fixed based on config value i used the option like DMW told