using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KongzhiTai
{
class Program
{
static void Main(string[] args)
{
//string str = "xiaobing";
//QueueenterFunction<string> queuenumber = new QueueenterFunction<string>();
//Console.WriteLine(queuenumber.EnterQueueAndReturn(str));
//Console.WriteLine(queuenumber.ToutQueue());
//Console.ReadKey();
QueueenterFunction<Document> queueObject = new QueueenterFunction<Document>();
bool a= queueObject.EnterQueueAndReturn(new Document("三国演义",20));
bool b= queueObject.EnterQueueAndReturn(new Document("水浒传", 30));
queueObject.DisplayAllDocumetn();
if (a&b)
{
Document d = queueObject.ToutQueue();
Console.WriteLine(d.Price);
}
Console.ReadKey();
}
}
public class QueueenterFunction<T> where T:IDocument
{
//创建一个队列
public readonly Queue<T> creatqueue = new Queue<T>();
//进队的方法
public bool EnterQueueAndReturn(T wantenterqueur)
{
creatqueue.Enqueue(wantenterqueur);
return IsEnterQueue(creatqueue);
}
//判断是否为空
public bool IsEnterQueue(Queue<T> isqueueempty)
{
return isqueueempty.Count > 0;
}
public T ToutQueue()
{
//null只能为引用类型
T doc=default(T);
lock (this)
{
doc = creatqueue.Dequeue();
}
return doc;
}
public void DisplayAllDocumetn()
{
foreach (T item in creatqueue)
{
Console.WriteLine(item.Title);
}
}
}
//接口
public interface IDocument
{
string Title { get; set; }
int Price { get; set; }
}
//实现接口的类
public class Document:IDocument
{
public Document(){}
public Document(string title,int price)
{
this.Title = title;
this.Price = price;
}
public string Title
{
get;
set;
}
public int Price
{
get;
set;
}
}
}