Professional Documents
Culture Documents
Lecture-08 Handling Higher Math
Lecture-08 Handling Higher Math
Visual Programming
Project
• {
• Count c = new Count();
• return win;
• public Form1()
• }
• {
• class Count • public void IncrementSpin()
• InitializeComponent();
• { • {
• }
• private int spin; • ++spin;
• private void button1_Click(object sender, EventArgs e)
• private int win; • }
• {
• public Count() • public void IncrementWin()
• Random rd = new Random();
• { • {
• label1.Text = rd.Next(10).ToString();
• spin = 0; • ++win;
• label2.Text = rd.Next(10).ToString();
• win = 0; • }
• label3.Text = rd.Next(10).ToString();
• } • public double Percent()
• c.IncrementSpin();
• public int getspin() • {
• if ((int.Parse(label1.Text)) == 7 || (int.Parse(label2.Text)) == 7 || (int.Parse(label3.Text)) == 7)
• { • double per=0.0;
• {
• return spin; • if(win!=0)
• c.IncrementWin();
• } • per=(double)spin/win;
• }
• • return per;
• label4.Text = c.Percent().ToString();
• }
• label5.Text = c.getspin().ToString();
• }
• label6.Text = c.getwin().ToString();
Partial Class
• A class can contain a number of methods, fields, and constructors, as
well as other items discussed in later chapters.
• A highly functional class can become quite large With C#, you can
split the source code for a class into separate files so that you can
organize the definition of a large class into smaller, easier to manage
pieces.
• Example.
Understanding static Methods and Data
• C# defines a modifier that you can use to declare that a variable is a nullable
value type A nullable value type behaves in a similar manner to the original
value type, but you can assign the null value to it.
• use the question mark (?) to indicate that a value type is nullable, like this
• Now you can test in the same way as a reference type whether a nullable
variable contains null:
Using Nullable Types
• You can assign an expression of the appropriate
value type directly to a nullable variable.