Can anyone tell me how can I generate a random string containing only letters in c#? I basically want a Random value and fill it in my form. I want this value to contain letters only? How can I do this?
            Asked
            
        
        
            Active
            
        
            Viewed 7,948 times
        
    -4
            
            
        - 
                    https://stackoverflow.com/questions/3066707/how-do-i-generate-a-random-string-of-up-to-a-certain-length – David Brabant Sep 24 '17 at 13:00
- 
                    or using LINQ [https://stackoverflow.com/questions/1344221/how-can-i-generate-random-alphanumeric-strings-in-c](https://stackoverflow.com/questions/1344221/how-can-i-generate-random-alphanumeric-strings-in-c) – styx Sep 24 '17 at 13:02
1 Answers
-1
            
            
        You could use the Random class to generate random numbers between 1 and 26, and convert that to characters. Something like this:
Random rnd = new Random();
int length =  20;
var str = "";
for(var i = 0; i < length; i++) 
{
    str += ((char)(rnd.Next(1,26) + 64)).ToString();
}
Console.WriteLine(str);
 
    
    
        Nisarg Shah
        
- 14,151
- 6
- 34
- 55
- 
                    3There are already plenty of example of previous questions and answers + the OP didn't shown any attempt he tried. – Orel Eraki Sep 24 '17 at 13:05
