带你走进C# 游戏开发等(五十九)擅长的领域"/>
夜光带你走进C# 游戏开发等(五十九)擅长的领域
夜光序言:
让人望眼欲穿是一种智慧,若是一览无余,不但乏味,而且令人厌倦。
正文:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApp1
{class 显示器 //写在这个里面一般都是用public{public string 出厂编号;public bool 是否开启; // true=开,false=关public int 尺寸;public int 颜色; //1表示白色,2表示黑色,3表示灰色public bool 是否有边框; //true=有,false=无public void 开关(){if(是否开启 == false){是否开启 = true;Console.WriteLine("显示器已经打开`");}else{是否开启 = false;Console.WriteLine("显示器已经关闭`");}}public void 显示信息(){Console.WriteLine("出厂编号" + 出厂编号);Console.WriteLine("尺寸" + 尺寸);Console.WriteLine("颜色" + 颜色);Console.WriteLine("是否有边框" + 是否有边框);}}class Date //我们构造一个{private int year;private int month;private int day;/// <summary>/// 带参数的构造器/// </summary>/// <param name="_year"></param>/// <param name="_month"></param>/// <param name="_day"></param>public Date(int _year,int _month,int _day){year = _year;month = _month;day = _day;}/// <summary>/// 不带参数的构造器,如果你创建了一个带参的,那么系统就不会自动帮你创建一个带参的,需要手写一个/// </summary>public Date() //这个时间是很有意义的,涉及到一个时间戳:this(1970,1,1){}public void print(){Console.WriteLine("{0}/{1}/{2}", year, month, day);}}class Test{public const int c = 1111;public readonly int ro = 1;public Test(int n) //我们定义一个整型n传进去{ro = n;}/// <summary>/// 考虑到使用static,我们新建下面这个////// </summary>}class Test2{public int n;}class Program //写在这个里面一般都是用static{static void Main(string[] args){#region static静态变量Test2 t21 = new Test2();Test2 t22 = new Test2();t21.n = 1111;t22.n = 1111;Console.WriteLine(t21.n);Console.WriteLine(t22.n);#endregion#region 案例 /* Test t1 = new Test(111111111); //把111111111赋值给n,n再赋值给ro//对象名.readonly 成员名Console.WriteLine(t1.ro);Console.WriteLine(Test.c);Test t2 = new Test(1111111111);Console.WriteLine(t2.ro);*/#endregion#region Date 日期调用/*//如果一个类没有构造器,那么C#会自动创造一个出来Date d = new Date(2020,1,1); //我们new一个date出来d.print();Date d2 = new Date();d2.print();*/#endregion#region new显示器,调用/* 显示器 m; //定义指向所创建的显示器的变量m = new 显示器(); //夜光:保存在m里面,那么这个m就是我们创建出来的显示器显示器 n = new 显示器(); //嗯唔//创建出来一台显示器m.出厂编号 = "LD11111111";m.尺寸 = 21;m.是否开启 = false;m.是否有边框 = true;m.颜色 = 2;m.显示信息();for(; ; ){Console.WriteLine("靓仔靓女~~按下回车键开关显示器");Console.ReadLine();m.开关();}*/#endregionConsole.ReadLine();}}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApp1
{class 显示器 //写在这个里面一般都是用public{public string 出厂编号;public bool 是否开启; // true=开,false=关public int 尺寸;public int 颜色; //1表示白色,2表示黑色,3表示灰色public bool 是否有边框; //true=有,false=无public void 开关(){if(是否开启 == false){是否开启 = true;Console.WriteLine("显示器已经打开`");}else{是否开启 = false;Console.WriteLine("显示器已经关闭`");}}public void 显示信息(){Console.WriteLine("出厂编号" + 出厂编号);Console.WriteLine("尺寸" + 尺寸);Console.WriteLine("颜色" + 颜色);Console.WriteLine("是否有边框" + 是否有边框);}}class Date //我们构造一个{private int year;private int month;private int day;/// <summary>/// 带参数的构造器/// </summary>/// <param name="_year"></param>/// <param name="_month"></param>/// <param name="_day"></param>public Date(int _year,int _month,int _day){year = _year;month = _month;day = _day;}/// <summary>/// 不带参数的构造器,如果你创建了一个带参的,那么系统就不会自动帮你创建一个带参的,需要手写一个/// </summary>public Date() //这个时间是很有意义的,涉及到一个时间戳:this(1970,1,1){}public void print(){Console.WriteLine("{0}/{1}/{2}", year, month, day);}}class Test{public const int c = 1111;public readonly int ro = 1;public Test(int n) //我们定义一个整型n传进去{ro = n;}/// <summary>/// 考虑到使用static,我们新建下面这个////// </summary>}class Test2{//夜光:教你如何理解 static →这个变量被这个类所有对象所共享,另外一门编程语言用shared来替换public static int n; }class Program //写在这个里面一般都是用static{static void Main(string[] args){#region static静态变量Test2 t21 = new Test2();Test2 t22 = new Test2();Test2.n = 1111;Test2.n = 11111111;Console.WriteLine(Test2.n);#endregion#region 案例 /* Test t1 = new Test(111111111); //把111111111赋值给n,n再赋值给ro//对象名.readonly 成员名Console.WriteLine(t1.ro);Console.WriteLine(Test.c);Test t2 = new Test(1111111111);Console.WriteLine(t2.ro);*/#endregion#region Date 日期调用/*//如果一个类没有构造器,那么C#会自动创造一个出来Date d = new Date(2020,1,1); //我们new一个date出来d.print();Date d2 = new Date();d2.print();*/#endregion#region new显示器,调用/* 显示器 m; //定义指向所创建的显示器的变量m = new 显示器(); //夜光:保存在m里面,那么这个m就是我们创建出来的显示器显示器 n = new 显示器(); //嗯唔//创建出来一台显示器m.出厂编号 = "LD11111111";m.尺寸 = 21;m.是否开启 = false;m.是否有边框 = true;m.颜色 = 2;m.显示信息();for(; ; ){Console.WriteLine("靓仔靓女~~按下回车键开关显示器");Console.ReadLine();m.开关();}*/#endregionConsole.ReadLine();}}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApp1
{class 显示器 //写在这个里面一般都是用public{public string 出厂编号;public bool 是否开启; // true=开,false=关public int 尺寸;public int 颜色; //1表示白色,2表示黑色,3表示灰色public bool 是否有边框; //true=有,false=无public void 开关(){if(是否开启 == false){是否开启 = true;Console.WriteLine("显示器已经打开`");}else{是否开启 = false;Console.WriteLine("显示器已经关闭`");}}public void 显示信息(){Console.WriteLine("出厂编号" + 出厂编号);Console.WriteLine("尺寸" + 尺寸);Console.WriteLine("颜色" + 颜色);Console.WriteLine("是否有边框" + 是否有边框);}}class Date //我们构造一个{private int year;private int month;private int day;/// <summary>/// 带参数的构造器/// </summary>/// <param name="_year"></param>/// <param name="_month"></param>/// <param name="_day"></param>public Date(int _year,int _month,int _day){year = _year;month = _month;day = _day;}/// <summary>/// 不带参数的构造器,如果你创建了一个带参的,那么系统就不会自动帮你创建一个带参的,需要手写一个/// </summary>public Date() //这个时间是很有意义的,涉及到一个时间戳:this(1970,1,1){}public void print(){Console.WriteLine("{0}/{1}/{2}", year, month, day);}}class Test{public const int c = 1111;public readonly int ro = 1;public Test(int n) //我们定义一个整型n传进去{ro = n;}/// <summary>/// 考虑到使用static,我们新建下面这个////// </summary>}class Test2{//夜光:教你如何理解 static →这个变量被这个类所有对象所共享,另外一门编程语言用shared来替换public static int n; }class BankAccount //我们定义一个这个类{public float balance; //余额public static float interest = 6.5f; //RMB:USDpublic BankAccount(float _balance){balance = _balance;}public float RmbToUsd() //定义一个转换的方法{return balance / interest;} }class Program //写在这个里面一般都是用static{static void Main(string[] args){BankAccount ba21 = new BankAccount(1111);BankAccount ba22 = new BankAccount(2222);Console.WriteLine("ba21.balance = {0}$", ba21.RmbToUsd());Console.WriteLine("ba22.balance = {0}$", ba22.RmbToUsd());#region static静态变量/* Test2 t21 = new Test2();Test2 t22 = new Test2();Test2.n = 1111;Test2.n = 11111111;Console.WriteLine(Test2.n);*/#endregion#region 案例 /* Test t1 = new Test(111111111); //把111111111赋值给n,n再赋值给ro//对象名.readonly 成员名Console.WriteLine(t1.ro);Console.WriteLine(Test.c);Test t2 = new Test(1111111111);Console.WriteLine(t2.ro);*/#endregion#region Date 日期调用/*//如果一个类没有构造器,那么C#会自动创造一个出来Date d = new Date(2020,1,1); //我们new一个date出来d.print();Date d2 = new Date();d2.print();*/#endregion#region new显示器,调用/* 显示器 m; //定义指向所创建的显示器的变量m = new 显示器(); //夜光:保存在m里面,那么这个m就是我们创建出来的显示器显示器 n = new 显示器(); //嗯唔//创建出来一台显示器m.出厂编号 = "LD11111111";m.尺寸 = 21;m.是否开启 = false;m.是否有边框 = true;m.颜色 = 2;m.显示信息();for(; ; ){Console.WriteLine("靓仔靓女~~按下回车键开关显示器");Console.ReadLine();m.开关();}*/#endregionConsole.ReadLine();}}
}
更多推荐
夜光带你走进C# 游戏开发等(五十九)擅长的领域
发布评论