C# 表达式学习记录

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;



namespace ExpressionLearnList
{
    class Program
    {
        static void Main(string[] args)
        {
            /*int x = 100;       //表达式的结果为single value
             (new Form()).ShowDialog();    //表达式的结果为object
             Action myAction = new Action(Console.WriteLine);   //表达式结果为method     委托
             System.Windows.Forms.Form myForm = new Form();     //表达式结果为namespace
             int y = x;

             Type myType = typeof(Int64);
             Console.WriteLine(myType.FullName);
            var x = 3 < 5;
            Console.WriteLine(x);        //表达式运算的结果不一定和操作数相同
            Student student = new Student();
            var x = student.ID;           //成员访问表达式的类型不定
            var y = student.Name;
            var result = Math.Pow(2, 3); //方法调用表达式的类型不定,依据方法返回值而定             
            List<int> intList = new List<int>() { 1, 2, 3 };
            Double[] doubleArray = new double[] { 1.0, 2.0, 3.0 };
            var x = intList[2];
            Console.WriteLine(x.GetType());  //由元素访问操作符构成的表达式,类型由所访问的集合的类型决定
            var y = doubleArray[1];
            Console.WriteLine(y.GetType());
            int x = 100;
            Console.WriteLine(x++); //100
            Console.WriteLine(x);   //101
            int y = 100;
            Console.WriteLine(++y);  //101
            Console.WriteLine(y);    //101       
            var x = default(Int32);
            Console.WriteLine(x);
            Console.WriteLine(x.GetType());
            var x = 5 > 3 ? 2 : 3.0;
            Console.WriteLine(x.GetType().FullName); //条件表达式的返回值由冒号两边的数的类型决定,哪个精度高类型就为哪个
            int x = 100;
            int y = x;
            Console.WriteLine(y = x);
            Console.WriteLine((y = x).GetType().FullName);       //赋值表达式的值为等号左边变量的值,类型为等号左边变量的类型

            Form myform = new Form();
            myform.Text = "Hello!";        //属性访问表达式
            myform.Load += Myform_Load;     //访问事件表达式
            myform.ShowDialog();            
            List<int> list = new List<int>() { 1, 2, 3 };
            int x = list[2];                //访问索引器
            Console.WriteLine(x); */     



        }

        private static void Myform_Load(object sender, EventArgs e)
        {
            Form form = sender as Form;
            if(form == null)
            {
                return;
            }
            form.Text = "new title";
        }

        class Student
        {
            public int ID;
            public string Name;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值