夜光带你走进C# 游戏开发等(五十九)擅长的领域

编程入门 行业动态 更新时间:2024-10-10 08:25:15

夜光<a href=https://www.elefans.com/category/jswz/34/1769690.html style=带你走进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# 游戏开发等(五十九)擅长的领域

本文发布于:2024-02-27 13:39:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1706752.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:带你   游戏开发   领域   五十九

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!