C# 作业

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        private int left = 0;
        private int right = 0;
        private Random rd = new Random();
        int num = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e){  }
        private void label3_Click(object sender, EventArgs e){  }
        private void label5_Click(object sender, EventArgs e){ }
        private void label7_Click(object sender, EventArgs e){ }
        private void label8_Click(object sender, EventArgs e){}
        private void Form1_Load(object sender, EventArgs e)
        {
            left = rd.Next(1, 1000);
            right = rd.Next(1, 1000);
            label1.Text = left.ToString();
            label3.Text = right.ToString();
        }
        
        private void button1_Click_1(object sender, EventArgs e)
        {
            string strResult = textBox1.Text;
            int val;
            try
            {
                  val= int.Parse(strResult);
            }
            catch(System.FormatException)
            {
                label5.Text = " 格式不对 请重新输入  "; return;
            }
            if (left + right == val)
            {
                label5.Text = " you are right ";
                num++;
                label8.Text = num.ToString();
            }
            else
            {
                label5.Text = " you are wrong ";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            left = rd.Next(1, 1000);
            right = rd.Next(1, 1000);
            label1.Text = left.ToString();
            label3.Text = right.ToString();
            textBox1.Text = "";
            label5.Text = "";
        }    
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    struct SomeVal { public Int32 x; }
    class SomeRef { public Int32 x; }
    class Program
    {
        static void Main(string[] args)
        {
            
 
    
            SomeVal v1 = new SomeVal() ; // 分配到    堆 (堆/栈)
            //Console.WriteLine(v1.x); //能运行吗?  不能        
            v1 = new SomeVal();
            Console.WriteLine(v1.x); //输出  0     
            v1.x =5; 
            Console.WriteLine(v1.x); //输出   5   

            SomeRef r1=new SomeRef(); 
           // Console.WriteLine(r1.x); //能运行吗?   不能    
            // 分配到    栈 (堆/栈)
            Console.WriteLine(r1.x); //输出    0  
            r1.x =5;
            Console.WriteLine(r1.x); //输出     5 

            SomeVal v2 = v1;
            SomeRef r2 = r1;
            v1.x = 9;
            r1.x = 8;
            Console.WriteLine(r1.x); //输出      8
            Console.WriteLine(r2.x); //输出      8
            Console.WriteLine(v1.x); //输出      9
            Console.WriteLine(v2.x); //输出      5

            Console.ReadKey();
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/Andromeda-Galaxy/p/10552325.html