mercredi 30 août 2017

Filling a list with random bytes

I'm trying to fill a buffer with random bytes. The buffer is defined as a list of bytes. This is something that I want to keep as it is. Here is the definition:

namespace NameofProject
{
    public partial class Form1 : Form
    {
    List<byte> buff = new List<byte>();
    }

}

And my first attempt is

public static void RandomFillBuffer()
{
   Random rnd = new Random();
   rnd.NextBytes(buff);
}

Yet this gives such an error for buff: An object reference is required for the non-static field, method, or property 'Form1.buff'

Then I just deleted the word "static" (I am not sure whether this is true) and it becomes "public void RandomFillBuffer()", but this time I am getting this error for buff: Argument 1: cannot convert from 'System.Collections.Generic.List' to 'byte[]'

I'd appreciate any help to solve any of the 2 errors if they make sense.




Aucun commentaire:

Enregistrer un commentaire