Создание MyQueue. Подскажите на сколько правильный код получился - C#
Формулировка задачи:
Создал свой класс MyQueue, реализовал в нем два метода (EnMyQueue и DeMyQueue) записывая все в List<>. Так же создал класс Student, который собственно и записываю в очередь(List). Подскажите на сколько правильно реализован код, и что нужно исправить.
public class MyQueue
{
private List<Student> _student = new List<Student>();
public void MyEnQueue(string name, string email)
{
_student.Add(new Student(name, email));
Console.WriteLine("\n MyEnQueue Student {0} \t in MyEnQueue, Sent the job to mail ? {1} ", name, email);
Console.Write("\n Content in MyEnQueue\t");
foreach (var VARIABLE in _student)
{
Console.Write(VARIABLE.Name + "," + VARIABLE.SentEmail + " ");
} }
public void MyDeQueue()
{
if (_student.Count > 0)
{
for (int i = 0; i < _student.Count; i++)
{
if (_student[i].SentEmail == "Yes")
{
Console.WriteLine("\n MyDeQueue Student {0} \t got a cup of coffee", _student[i].Name);
_student.RemoveAt(i);
break;
}
else
{
Console.WriteLine("\n MyDeQueue Student {0} \t not got a cup of coffee", _student[i].Name);
_student.RemoveAt(i);
break;
} }
Console.WriteLine();
}
else
{
Console.WriteLine("\n MyQueue empty");
} }}
public class Student
{
private string name, sentEmail;
public string Name
{
get { return name; }
set { }
}
public string SentEmail
{
get { return sentEmail; }
set { }
}
public Student(string _name, string _sentEmail)
{
name = _name;
sentEmail = _sentEmail;
}}
class Program
{
static void Main(string[] args)
{
MyQueue myQueue = new MyQueue();
myQueue.MyEnQueue("Ivan", "Yes");
myQueue.MyEnQueue("Gena", "No");
myQueue.MyEnQueue("Galina", "Yes");
myQueue.MyEnQueue("Stepan", "No");
Console.WriteLine("\n \n Sent task the email, got a cup of coffee \n");
myQueue.MyDeQueue();
myQueue.MyDeQueue();
myQueue.MyDeQueue();
myQueue.MyDeQueue();
myQueue.MyDeQueue();
Console.ReadLine();
}
}Решение задачи: «Создание MyQueue. Подскажите на сколько правильный код получился»
textual
Листинг программы
public class MyQueue<T>
{
private readonly List<T> items = new List<T>();
public void Enqueue(T item)
{
items.Add(item);
}
public T Dequeue()
{
var res = items[0];
items.RemoveAt(0);
return res;
}
public int Count{ get { return items.Count; } }
}