编程语言
首页 > 编程语言> > 20210507 C#课堂练习

20210507 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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
             try
             {
                 double y;
                 y = -5.6 % 4.6;
                 int[] a = new int[20];
                 a[30] = 90;                 
             }
             
             catch(IndexOutOfRangeException ey){
                 try
                 {
                     float x = float.Parse(textBox1.Text);
                     float y = float.Parse(textBox2.Text);
                     float z = (float)Math.Sqrt(x);
                     textBox3.Text = z.ToString();
                 }
                 catch (FormatException ez){
                     MessageBox.Show("错误z:" + ez.ToString());
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show("错误x:" + ex.ToString());

             }
        }        

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                float x = float.Parse(textBox1.Text);
                float y = float.Parse(textBox2.Text);
                float z = x / y;
                textBox4.Text = z.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误:" + ex.ToString());
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using abc.xyz;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            A a = new A();
            a.x = 9;//a是namespace ConsoleApplication1中的类A的对象
            abc.A aa = new abc.A();
            aa.y = 8;//aa是namespace abc中的类A的对象
            abc.xyz.A aaa = new abc.xyz.A();
            aaa.z = 18;//aaa是namespace abc.xyz中的类A的对象
            abc.xyz.X xx = new abc.xyz.X();
            xx.www = 1919;
            xx.www = 10;
            try{           
            
                int u = a.x / xx.www;
                Console.WriteLine("haha.");
            }
            catch(Exception ex){
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }
    }
    class A {
        public int x;
    }
    class B { 
    }

}
namespace abc
{
    namespace xyz
    {
        class A {
            public int z;
        }
        class X
        {
            public int www;
        }
    }
    class A
    {
        public int y;
    }
}

标签:abc,课堂练习,C#,Text,xyz,float,System,20210507,using
来源: https://www.cnblogs.com/iamrich/p/14975080.html