Get random byte array in CSharp

Description

The following code shows how to get random byte array.

Example


// w w w. j  av  a  2 s . c om
using System;

public class Example 
{
    public static void Main() 
    {
        Random rnd = new Random();
        Byte[] b = new Byte[10];
        rnd.NextBytes(b);
        for (int i = 0; i <= b.GetUpperBound(0); i++) 
            Console.WriteLine("{0}: {1}", i, b[i]);  
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Development »




Console
Encoding
Environment
Random