Get Random String for size - CSharp System

CSharp examples for System:Random

Description

Get Random String for size

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from  ww  w  . j a  va2s .  c om*/

public class Main{
        public static string GetRandomString(int size)
        {
            const string chars = "ABCDEFGHIJKLMNOPRSTUVWXYZabcdefghijklmnoprstuvwxyz0123456789";
            
            var buffer = new char[size];
            for (int i = 0; i < size; i++)
                buffer[i] = chars[_random.Next(chars.Length)];
            return new string(buffer);
        }
}

Related Tutorials