Hi everyone I am trying to generate 6 different numbers on the same line in c# but the problem that i face is some of the numbers are repeating on the same line.Here is my c
I've switched your for loop with a do...while loop and set the stopping condition on the list count being smaller then 6. This might not be the best solution but it's the closest to your original code.
List listNumbers = new List();
do
{
int numbers = rand.Next(1,49);
if(!listNumbers.Contains(number)) {
listNumbers.Add(numbers);
}
} while (listNumbers.Count < 6)