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;
}
}
}
C# 表达式学习记录
最新推荐文章于 2025-03-10 19:23:55 发布