locked
Byte Array RRS feed

  • Question

  • does anyone know how to empty an array? what i mean by that is clear it so that it has no values. i know Array.Clear is supposed to do this but i cant get that option with a Byte Array
    Sunday, September 25, 2005 11:58 PM

Answers

  • Hi

    Do you mean emptying as in removing all items? coz the initialize method only initializes every item in an array (not removing them)... But if you want to really remove all items then you'll have to redeclare it:

    byte[] myByte = new byte[30];
    Console.WriteLine(myByte.Length.ToString());
    myByte = new byte[]{};
    Console.WriteLine(myByte.Length.ToString());

     

    cheers,

    Paul June A. Domag

    Monday, September 26, 2005 6:57 AM

All replies

  • Hi,

    I think you can do that by calling the array's Initialize method:

    byte[] myByte = new byte[30];

    myByte.Initialize();

     

     

     

    cheers,

    Paul June A. Domag

    Monday, September 26, 2005 5:54 AM
  • doesnt work. my byte array is supposed to be a buffer that im supposed to send over a Stream in a Socket connection

    i dont know what buffer.Initialize does but it didnt do it.
    Monday, September 26, 2005 6:42 AM
  • Hi

    Do you mean emptying as in removing all items? coz the initialize method only initializes every item in an array (not removing them)... But if you want to really remove all items then you'll have to redeclare it:

    byte[] myByte = new byte[30];
    Console.WriteLine(myByte.Length.ToString());
    myByte = new byte[]{};
    Console.WriteLine(myByte.Length.ToString());

     

    cheers,

    Paul June A. Domag

    Monday, September 26, 2005 6:57 AM
  • allright. i'll try that out. thanks
    Monday, September 26, 2005 10:24 PM
  • byte[] myByte = new byte[30];

    for (int i = 0; i < myByte.Length; i++){
         myByte[i] = 0;

    }

    Tuesday, January 3, 2012 11:17 PM