-4

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?

2

1 Answer 1

-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);
Sign up to request clarification or add additional context in comments.

1 Comment

There are already plenty of example of previous questions and answers + the OP didn't shown any attempt he tried.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.