0

How do i change an int value to a specific number in C#?

Why can't you just do this? int number = 1; Console.WriteLine(number); number = 2; Console.WriteLine(number); number = 3; Console.WriteLine(number);

7th Apr 2023, 2:05 PM
Mark Gavrilov
Mark Gavrilov - avatar
5 Answers
+ 4
Well, you can do this. What are you trying to do? What issues are you encountering?
7th Apr 2023, 2:50 PM
Lisa
Lisa - avatar
0
It says a local variable " " is already defined
8th Apr 2023, 6:02 AM
Mark Gavrilov
Mark Gavrilov - avatar
0
Where did you define it? Please link your complete code.
8th Apr 2023, 6:16 AM
Lisa
Lisa - avatar
0
int RanNum =(Convert.ToInt32(Console.ReadLine())); int RanNum2 =(Convert.ToInt32(Console.ReadLine())); Random rd = new Random(); int rand_num = rd.Next(RanNum,RanNum2); int rand_num = rd.Next(RanNum,RanNum2); int rand_num = rd.Next(RanNum,RanNum2); int rand_num = rd.Next(RanNum,RanNum2); int rand_num = rd.Next(RanNum,RanNum2); Console.WriteLine(rand_num); Console.WriteLine(rand_num); Console.WriteLine(rand_num); Console.WriteLine(rand_num); Console.WriteLine(rand_num);
8th Apr 2023, 7:03 AM
Mark Gavrilov
Mark Gavrilov - avatar
0
Is this the code mentioned in the description? You defined int rand_num multiple times. Initialize rand_num ONCE. Then use it: Sample a number, print the number, sample a new number...
8th Apr 2023, 7:08 AM
Lisa
Lisa - avatar