473,394 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

byte array Vs List<byte>

1
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.
Aug 8 '08 #1
2 5818
Curtis Rutland
3,256 Expert 2GB
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.
Aug 8 '08 #2
r035198x
13,262 8TB
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.
Aug 8 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Vince | last post by:
Hi, I have replaced my BYTE* by a vector<BYTE> and before I used to do : void CCardRecord::GetRecData(int nOffset, int nDataSize, CString& csValue) { BYTE *pTmp = NULL; pTmp = new BYTE;...
4
by: zon7mail | last post by:
I've two functions. One is managed and receives an array, and the other is unmanaged and receives a pointer, just like this class A { int Foo(unsigned char* m){}; ... } ref class B {
1
by: Hyun-jik Bae | last post by:
Hi, I heard roughly that List<bytekeep data in one block like byte. Is that really true? Please reply. Thanks in advance. Hyun-jik Bae
2
by: blueflyy | last post by:
Hello, I wish to initialize a vector<BYTE> from an existing BYTE array. Simple example: BYTE buf = {0,1,2,3,4,5}; std::vector<BYTE> vec(buf, buf + sizeof(buf)/sizeof(buf));
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.