Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare a byte ArrayList

Tags:

c#

arraylist

byte

I am trying to do

var mahByteArray = new ArrayList<byte>();

And it does not work. It says this:

The non-generic type 'System.Collectios.ArrayList' cannot be used with type arguments

What is the proper way to do declare a byte ArrayList?

like image 882
meme Avatar asked Dec 28 '25 13:12

meme


2 Answers

You are confusing Java ArrayList collections with C# List generic collections. Both are used to declare collections, but the first one is used in Java as being a type defined in the generic class List for Collections framework and in the last one is used in C# language as an implicit generic type.

So, you must declare as being a List type. See details on List.

var mahByteArray = new List<byte>();

or

List<byte> mahByteArray = new List<byte>() { 2, 3, 4 };
like image 157
e2a Avatar answered Dec 31 '25 03:12

e2a


sure you can use a ArrayList

var mahByteArray = new ArrayList();
mahByteArray.Add((byte) 230);
like image 37
fubo Avatar answered Dec 31 '25 03:12

fubo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!