I have problems when trying to generate random numbers in Visual C#.Net. What I am trying to do is after I declare the variable called randomslot1, randomslot2, and randomslot3 for Random, I can assign those three variables to each of 3 text box.
Here's the code for it:
The compiler told me that I can't convert from int to string, and the .Net help told me that I need to provide my conversion runtime but I don't know the code for it...Code:// C# Code: /// <summary> /// This is the code for the button. Once pressed, the button that /// was pressed will generate numbers to each of the text boxes. /// // Note: This is just a test. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void SlotSpin_Click(object sender, System.EventArgs e) { // A constant variable... const int maxnumber = 10; // Declare a random variable for each of the slots. Random randomslot1 = new Random(unchecked((int)DateTime.Now.Ticks)); Random randomslot2 = new Random(unchecked((int)DateTime.Now.Ticks)); Random randomslot3 = new Random(unchecked((int)DateTime.Now.Ticks)); // Send each of those as string. randomslot1.ToString(); randomslot2.ToString(); randomslot3.ToString(); // Send those numbers to each of the text box // with a maximum value of 10 each having a different value. Slot1.Text = (string)randomslot1.Next(maxnumber); Slot2.Text = (string)randomslot2.Next(maxnumber); Slot3.Text = (string)randomslot3.Next(maxnumber); }



LinkBack URL
About LinkBacks


