尝试在C#中添加和删除队列中的节点.但是,当尝试使用时,front.Next我得到一个编译器错误,该定义未包含在内.
class Queue<T>
{
int count = 0;
Node<T> front = null;
Node<T> end = null;
public void Enqueue(T obj)
{
if (count == 0)
{
front = new Node<T>(obj);
}
else
{
Node<T> newEnd = new Node<T>(obj);
newEnd.Next = end;
count++;
end = newEnd;
}
}
public T Dequeue(T obj)
{
Node<T> newFront = new Node<T>(obj);
newFront = front.Next;
count--;
front = newFront;
return front;
}
}
Run Code Online (Sandbox Code Playgroud) 我试图检查c#中是否有某种类型的类.它会在表单上打印出某些标签,具体取决于它的类型.这是我到目前为止所做的,它适用于"if"语句.但是,我收到"无法转换类型对象"的错误.在这种情况下是否可以使用if-else语句?
public void ShowStaffData(string pName)
{
//Gets Staff Details from the name slected int he list box in the form
people.CreatePeople();
var currentPerson =
people.person.Where(p => p.Forename + " " + p.Surname == pName);
// How the info is printed out if person selected in
// a member of Accademic Staff
AccademicStaff accademic = currentPerson as AccademicStaff;
if (currentPerson!=null)
{
foreach (AccademicStaff accStaff in currentPerson)
{
label9.Text = accStaff.Forename + " " + accStaff.Surname;
label10.Text = accStaff.IdentificationNumber.ToString();
label11.Text = accStaff.DateOfBirth; …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的文本文件
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 …Run Code Online (Sandbox Code Playgroud)