0.定义变量的时候,养成设置初始值的习惯 如int a=0;
1.注意这种写法
public bool Compare(Client other)
{
return this.TotalMoney > other.TotalMoney;//值得注意的写法
}
2.如果遇到不懂的按F12查看定义
3.学习方法---看得懂代码,听得懂 自己建个空白项目的时候就头脑空白
---基础不牢
怎么办?
练------怎么练?
第一遍:跟着老师打,明白每句代码意思
第二遍:对着PPT题目自己独立写一遍,如果再卡,就重新看下视频
第三遍
。
。
。
。
总之一定要多动手。
4.思考 类与类之间的关系
5.思路 思路 还是思路
当天代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Task2
{
public class Order
{
private int _Number;
public int Number//只读订单编号
{
get
{
return _Number;
}
}
private static int _count = 0;//记录订单数
private int _Money;//金额
public int Money
{
get
{
return this._Money;
}
set
{
if (value > 0)
{
this._Money = value;
}
}
}
public Order(): this(0)
{
}
public Order(int money)
{
this._Money = money;
Order._count++;//调用类的时候开始统计数据
_Number = Order._count;//自增的编号通过此代码来实现
}
}
public class Client
{
public string _Name;//客户名字
public Order CreateNewOrder(int money)//创建新订单
{
Order order = null;
order = new Order(money);
//添加到orders里面
orders.Add(order);
return order;
}
private List<Order> orders = new List<Order>();
public int TotalMoney//订单总金额
{
get
{
int total = 0;//定义的临时变量来接收总金额
foreach (Order order in orders)
{
total += order.Money;
}
return total;
}
}
public bool Compare(Client other)
{
return this.TotalMoney > other.TotalMoney;//值得注意的写法
}
public Client():this("无名")
{
}
public Client(string name)
{
this._Name = name;
}
}
class Program
{
static void Main(string[] args)
{
Client c1 = new Client("张三");
Client c2 = new Client("李四");
c1.CreateNewOrder(100);
c2.CreateNewOrder(500);
Console.WriteLine(c1.TotalMoney);
Console.WriteLine(c1.Compare(c2));
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Task2
{
public class Order
{
private int _Number;
public int Number//只读订单编号
{
get
{
return _Number;
}
}
private static int _count = 0;//记录订单数
private int _Money;//金额
public int Money
{
get
{
return this._Money;
}
set
{
if (value > 0)
{
this._Money = value;
}
}
}
public Order(): this(0)
{
}
public Order(int money)
{
this._Money = money;
Order._count++;//调用类的时候开始统计数据
_Number = Order._count;//自增的编号通过此代码来实现
}
}
public class Client
{
public string _Name;//客户名字
public Order CreateNewOrder(int money)//创建新订单
{
Order order = null;
order = new Order(money);
//添加到orders里面
orders.Add(order);
return order;
}
private List<Order> orders = new List<Order>();
public int TotalMoney//订单总金额
{
get
{
int total = 0;//定义的临时变量来接收总金额
foreach (Order order in orders)
{
total += order.Money;
}
return total;
}
}
public bool Compare(Client other)
{
return this.TotalMoney > other.TotalMoney;//值得注意的写法
}
public Client():this("无名")
{
}
public Client(string name)
{
this._Name = name;
}
}
class Program
{
static void Main(string[] args)
{
Client c1 = new Client("张三");
Client c2 = new Client("李四");
c1.CreateNewOrder(100);
c2.CreateNewOrder(500);
Console.WriteLine(c1.TotalMoney);
Console.WriteLine(c1.Compare(c2));
}
}
}