本帖最后由 inside 于 2020-4-24 17:14 编辑
代码提示在预览的时候是可以高亮显示的,为什么在发布后就不行了?
- 1.Prototype 抽象原型
2.ConcretePrototype1 具体原型(实现 Prototype)
3.Client
# 编辑时
发布后
using System;
///
/// C#语言
///
namespace DesignMode
{
//抽象原型
abstract class Prototype
{
private string id;
public Prototype(string id)
{
this.id = id;
}
public string Id
{
get { return id; }
}
public abstract Prototype Clone();
}
//具体原型 1
class ConcretePrototype1rototype
{
public ConcretePrototype1(string id) : base(id)
{
}
public override Prototype Clone()
{
return new ConcretePrototype1(this.Id) as Prototype;
}
}
//具体原型种类 2
class ConcretePrototype2 : Prototype
{
private string name;
public string Name { get { return name; } }
private int age;
public int Age { get { return age; } }
public ConcretePrototype2(string id, string name, int age) : base(id)
{
this.name = name;
this.age = age;
}
public override Prototype Clone()
{
return new ConcretePrototype2(this.Id, this.Name, this.Age) as Prototype;
}
}
//客户端测试代码
class Client
{
public void Test()
{
ConcretePrototype1 p1 = new ConcretePrototype1("rototype1");
ConcretePrototype1 c11 = p1.Clone() as ConcretePrototype1;
ConcretePrototype1 c12 = p1.Clone() as ConcretePrototype1;
ConcretePrototype2 p2 = new ConcretePrototype2("rototype2", "种类 2", 18);
ConcretePrototype2 c21 = p2.Clone() as ConcretePrototype2;
ConcretePrototype2 c22 = p2.Clone() as ConcretePrototype2;
Console.WriteLine("原型 1{0}", p1.Id);
Console.WriteLine("原型 1 克隆{0}", c11.Id);
Console.WriteLine("原型 1 克隆{0}", c12.Id);
Console.WriteLine("原型 2{0},{1},{2}", p2.Id, p2.Name, p2.Age);
Console.WriteLine("原型 2 克隆{0},{1},{2}", c21.Id, c21.Name, c21.Age);
Console.WriteLine("原型 2 克隆{0},{1},{2}", c22.Id, c22.Name, c22.Age);
}
}
class Program
{
static void Main(string[] args)
{
Client client = new Client();
client.Test();
Console.Read();
}
}
}
void menu()
{
printf("##########################\n");
printf("## 欢迎来到扫雷游戏 ##\n");
printf("##########################\n");
printf("#1.开始游戏 2.结束游戏#\n");
printf("##########################\n");
printf("您的选择是");
} |