Why can\'t I get this random number generating form to work? it already has the
ID: 3743902 • Letter: W
Question
Why can't I get this random number generating form to work? it already has the dll file system.data using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp3 { public partial class Form1 : Form { Random Ran = new Random(); int value; public Form1() { InitializeComponent(); } private void Button1_Click(object sender, EventArgs e) { value = Ran.Next(1, 69); label1.Text = value.ToString(); } } }
Explanation / Answer
Your code is right without any syntax errors. Based on your code, a random number is generated only when the Button1_Click method is executed. Then the random generated value is assigned to the label lable1. So click the button to generate the random number.
If you want to get the random number generated automatically, include the lines in the form1 constructor.
**Comment for any queries. Happy to help ...:)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.