Pick random char

前端 未结 11 1459
名媛妹妹
名媛妹妹 2021-01-03 20:57

i have some chars:

chars = \"$%#@!*abcdefghijklmnopqrstuvwxyz1234567890?;:ABCDEFGHIJKLMNOPQRSTUVWXYZ^&\".ToCharArray();

now i\'m lookin

11条回答
  •  悲哀的现实
    2021-01-03 21:27

    Your Code is good, you just need to change 'a' to 'A'

    static Random random = new Random();
            public static char GetLetter()
            {
                // This method returns a random lowercase letter
                // ... Between 'a' and 'z' inclusize.
                int num = random.Next(0, 26); // Zero to 25
                char let = (char)('A' + num);
                return let;
            } 
    

    This code same as mentioned in the question , just change char let = (char)('A' + num); , it returns upper case letters.

    Thanks!!!

提交回复
热议问题