``
```回顾 、、、、
/*using System;
namespace test1
{
class Programe10
{
enum State
{
在线, 下线, 忙碌中, 隐身
}
struct Student
{
public int Id;
public string Name;
}
delegate int getnum(int num1 ,int num2);
static int MAX(int num1, int num2)
{
if(num1 > num2)
{
return num1;
}
return num2;
}
struct Preson
{
public string name;
public int age;
public string number;
}
*//* // 创建一个类
class Animal{
// 构造函数
// 字段
public string name;
public int age;
// 属性
//方法
}
*//* static void Main(string[] args)
{
*//* Animal dog; // 声明一个dog 对象
dog =new Animal(); // 创建一个dog对象
dog.age = 13;
*/
/* //枚举类型回顾
State statel;
statel = State.忙碌中; // 遍历枚举类型中的名字
foreach (string name in Enum.GetNames(typeof(State)))
{
Console.WriteLine(name);
// 遍历枚举类型中名字对应的值
}
foreach (int num in Enum.GetValues(typeof(State)))
{
Console.WriteLine(num);
}
// 结构体回顾
Student student1;
student1.Id = 10;
student1.Name = "xukun";
// 委托回顾 相当于定义一个没有函数体的函数和目标函数有相同的返回值和参数使用委托指向目标函数
getnum getn;
getn = MAX;
int a= getn(32, 20);
Console.WriteLine(a);
//练习题1
//编写一个程序,定义结构(有姓名,年龄,手机号码三个字段),再定义一个一维数组,把结构作为
//数组元素类型,存入数据,然后依次输出。
Preson preson1;
preson1.name = "xukun";
preson1.age = 20;
preson1.number="18779656828";
Preson[] preson2 = new Preson[1] { preson1 };
foreach(Preson i in preson2)
{
Console.WriteLine(i.name);
Console.WriteLine(i.age+"");
Console.WriteLine(i.number);
}
*//*
// 类(方法 ,属性,字段 )增加代码的复用 对象由类生成的 对象(具体) attack的方法
// 创建一个attack 方法公用会有什么问题呢 ??? attack 用到对象的一些属性 或调用其他的方法
}
}
}*/
、、、 面向对象
/*using System;
namespace test1
{
// 车类
public class Vehicle
{
// 构造函数
public Vehicle(int speed2, int MaxSpeed2, int Weight2)
{
this.Weight = Weight2;
this.MaxSpeed = MaxSpeed2;
this.speed = speed2;
}
public int speed;
public int MaxSpeed;
public int Weight;
public void run()
{
Console.WriteLine("i is a car weight {0}max seepd is{1},speed{2}", Weight, MaxSpeed, speed);
}
public void stop()
{
Console.WriteLine("i stop in the load");
}
}
// 创建一个动物类
class Animal
{
// 构造函数
public Animal(string name1, int age1, int num2)
{
this.name = name1;
this.age = age1;
this.num = num2;// this 是指向当前创建的对象
}
// 字段
public string name;
public int age;
public int num1 = 1;
// 属性
public int num
{
get // 设置可以读
{
Console.WriteLine("我是get ,只有属性被读取就会执行");
return num1; // 表示 属性杯访问的是时候可以访问该代码同时返回一个值
}
set // 设置可以写
{
num1 = value;
Console.WriteLine("新的值还没有给num赋值", value); // set 表示当设置num 值的时候会执行value的新的值、
}
}
//方法
public void show()
{
Console.WriteLine("我是{0}今年{1}", name, age);
}
}
class Programe3
{
// 主函数
static void Main(string[] args)
{
Vehicle car1;
car1 = new Vehicle(60, 200, 1000);
car1.run();
car1.stop();
Animal dog;
Animal cat;
dog = new Animal("小萨", 3, 111);
cat = new Animal("小黑", 2, 222);
dog.show();
cat.show();
*//* Animal dog; // 声明一个dog 对象
dog = new Animal(); // 创建一个dog对象
dog.age = 13;
dog.name = "xiaoming";
dog.show(); // 使用方法
dog.num = 10;
Console.WriteLine(dog.num);*//*
}
}
}*/
、、、、 面向对象_继承;
using System;
namespace test1
{
// 创建一个基类 (父亲)
public class Enemy
{
// 构造函数
/* public Enemy (int life)
{
this.life = life;
}*/
// 字段
public int life;
// 方法
public virtual void move() // virtual 虚拟方法 调用move 方法的时候如果子类有move方法
// 就调用 子类的move 的方法
{
Console.WriteLine("怪物移动"+life);
}
}
// 创建 一个派生类 (子类)
class Boss: Enemy // 用冒号 来继承父类
{
// 虚拟方法(重写父类中的方法)
public override void move()
{
Console.WriteLine(1);
}
}
//(简答题)创建类MyMath,计算圆的周长、面积和对应球的体积。
//1.创建类MyMath类,包含常量PI;静态方法周长,静态方法面积,非静态方法体积
//。2.输入半径,输出周长,面积和体积
class MyMath
{
//构造
public MyMath(double PI)
{
this.PI = PI;
}
//字段
public Double PI;
public Double R;
//方法
public void zhouchang(double R)
{
double zc;
zc = 2 * PI * R;
Console.WriteLine("周长"+zc);
}
public void mianji(double R)
{
double mj;
mj = PI * R * R;
Console.WriteLine("面积"+mj);
}
public void tiji(double R)
{
Double tj;
tj = PI * R * R;
Console.WriteLine("体积是"+tj*3/4);
}
}
class Programe3
{
static void Main(string[] args)
{
//圆
MyMath mymath;
mymath = new MyMath(3.14);
mymath.zhouchang(10); // 输出周长
mymath.mianji(10);// 输出 面积
mymath.tiji(10);// 输出 体积
// 父类
Enemy enemy;
enemy = new Enemy();
enemy.move();
// 子类
Boss boss;//声明
boss = new Boss(); // 定义
boss.move();
}
}
}