Connecting Tech Pros Worldwide Forums | Help | Site Map

byte array Vs List<byte>

Newbie
 
Join Date: Aug 2008
Posts: 1
#1: Aug 8 '08
I have a requirement in the C# app to find if a byte exists as part of byte array and take decision based on that.

I came across few of two ways to do that.

Use the basic byte[] Array and use for loop to find the existence of the byte i am looking for

(Or)

Use some thing like List<byte> byteList and then "byteList.Contains((byte)byteVar)" .

Not very sure which one is advised performance wise. Would it better to always use generic List or its suggested only when you have large number of elements.

insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#2: Aug 8 '08

re: byte array Vs List<byte>


Well, as far as I know, the .Contains method does loop through the array anyway. I'm not sure that you'd see any real performance difference between the two, although I may be wrong.

Perhaps you could write a simple time trial program to determine which one is quicker. Use different cases (large arrays, small arrays) and see which one takes less total time from start to finish. I'd like to hear the answer, if you get one.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#3: Aug 8 '08

re: byte array Vs List<byte>


Usually the decision to use List vs array is made based on whether you know the exact number of elements that you want to store or not and whether the list's size needs to change dynamically or will just remain constant.
Reply


Similar .NET Framework bytes