This question already has an answer here:
- Benefits of using the conditional ?: (ternary) operator 17 answers
- How does the ternary operator work? 12 answers
I'm a beginner programmer doing some practice projects. Im making a program right now which needs a random number between certain ranges. I need to make random strings of letters of some length and the way I thought of doing it was using a for loop which casts char values to the ints. I can do it easily with just lowercase letters, but now that I want to add uppercase letters as well I need the range to be 1-26 ,skip, 97-122. I found this piece of code on another thread:
int num = rnd.Next(1, 3)==1 ? rnd.Next(10, 21) : rnd.Next(50,61);
I don't quite understand what some parts mean(the ==1 ? and the :). I looked through the comments on the thread but no one explained what was happening. Can someone break it down for me? Thank you.
Aucun commentaire:
Enregistrer un commentaire