.Net学习笔记----2015-07-10(基础复习和练习09)

1、请将字符串数组{ "中国", "美国", "巴西", "澳大利亚", "加拿大" }中的内容反转。然后输出反转后的数组。不能用数组的Reverse()方法。

 

        static void Main(string[] args)
        {
            string[] strs = { "中国", "美国", "巴西", "澳大利亚", "加拿大", "西班牙" };
            //第一个和最后一个交换
            //交换strs.Length/2次
            for (int i = 0; i < strs.Length / 2; i++)
            {
                string temp = strs[strs.Length-1-i];
                strs[strs.Length - 1 - i] = strs[i];
                strs[i] = temp;
            }
            for (int i = 0; i < strs.Length; i++)
            {
                Console.Write(strs[i] + " ");
            }
            Console.ReadKey();
        }

 

2、创建一个Person类,属性:姓名、性别、年龄;方法:SayHi() 。再创建一个Employee类继承Person类,扩展属性Salary,重写SayHi方法。

父类:

 

    class Person
    {
        public string Name
        {
            get;
            set;
        }
        public int Age
        {
            get;
            set;
        }
        public char Gender
        {

        }

        public virtual void SayHi()
        {
            Console.WriteLine("我是父类的SayHi");
        }
    }

 

子类:

    class Employee : Person
    {
        public double Salary
        {
            get;
            set;
        }

        public override void SayHi()
        {
            Console.WriteLine("子类重写父类");
        }
    }

使用WinForm窗体,制作一个简易计算器,默认为“请选择”。要求具有+-*/功能,当用户点击“等于”按钮时,如果输入的为非数字则提示用户:

 

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.SelectedIndex = 0;
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            try
            {
                int n1 = Convert.ToInt32(textBox1.Text.Trim());
                int n2 = Convert.ToInt32(textBox2.Text.Trim());
                string oper = comboBox1.SelectedItem.ToString();
                switch (oper)
                {
                    case "+": label1.Text = (n1 + n2).ToString();
                        break;
                    case "-": label1.Text = (n1 - n2).ToString();
                        break;
                    case "x": label1.Text = (n1 * n2).ToString();
                        break;
                    case "/": label1.Text = (n1 / n2).ToString();
                        break;
                    default: MessageBox.Show("请选择正确的运算符");
                        break;
                }
            }
            catch
            {
                MessageBox.Show("请输入正确的数字");
            }
        }
    }

 

转载于:https://www.cnblogs.com/mikie/p/4636040.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值