interface ISpeak
{
string Hello();
}
class Baby : ISpeak
{
public string Hello()
{
return "哇哇哇";
}
}
interface IBattle
{
int Attack();
int Move();
void Jump();
}
interface IRest
{
void SitDown();
void Sleep();
}
interface IPlayer : IBattle,IRest
{
}
class Soldier : IPlayer
{
private string name;
private int attack;
private int speed;
public Soldier(string name, int attack, int speed)
{
this.name = name;
this.speed = speed;
this.attack = attack;
}
public int Attack()
{
return attack;
}
public void Jump()
{
Console.WriteLine(name + "跳躍");
}
public int Move()
{
return speed;
}
public string Name()
{
return name;
}
public void SitDown()
{
Console.WriteLine(name+"坐下了");
}
public void Sleep()
{
Console.WriteLine(name+"睡覺了");
}
}
interface IUSB
{
string ReadData();
}
public abstract class MemoryDevice : IUSB
{
public string ReadData()
{
return "正在閱讀數據";
}
public abstract void Description(MemoryType memoryType);
}
public enum MemoryType
{
SolidStateDisk,
HardDisk,
UDisk
}
class Computer : MemoryDevice
{
public override void Description(MemoryType memoryType)
{
switch (memoryType)
{
case MemoryType.SolidStateDisk:
Console.WriteLine("固態硬盤" + ReadData());
break;
case MemoryType.HardDisk:
Console.WriteLine("機械硬盤" + ReadData());
break;
case MemoryType.UDisk:
Console.WriteLine("U盤" + ReadData());
break;
}
}
}
class SingletonClass<T> where T : class, new()
{
private static T singleton;
public static T Singleton
{
get
{
if (singleton == null)
{
singleton = new T();
}
return singleton;
}
}
}
class Person : SingletonClass<Person>
{
public void cw()
{
Console.WriteLine("666");
}
}
class Program
{
static void Main(string[] args)
{
Baby baby = new Baby();
Console.WriteLine(baby.Hello());
Console.WriteLine("-------------");
Soldier soldier = new Soldier("zw", 1000, 300);
Console.WriteLine(soldier.Name() + "的攻擊力是" + soldier.Attack());
Console.WriteLine(soldier.Name() + "的移速是" + soldier.Move());
soldier.Jump();
soldier.SitDown();
soldier.Sleep();
Console.WriteLine("-------------");
Computer computer = new Computer();
Console.WriteLine("插入的是什麼?1-固態硬盤。2-機械硬盤。3-U盤");
MemoryType memoryType=new MemoryType();
memoryType=(MemoryType )int.Parse(Console.ReadLine())-1;
computer.Description(memoryType);
}