例如,这两种方法都需要更新count
变量:
public void AddFront(T data) {
Node<T> newNode = new Node<T>(data, null, null);
if (count == 0) {
head = tail = newNode;
}
else {
newNode.Next = head;
head.Previous = newNode;
head = newNode;
}
// don't forget
count++;
}
public void AddBack(T data) {
Node<T> newNode = new Node<T>(data, null, null);
if (count == 0) {
head = tail = newNode;
}
else {
newNode.Previous = tail;
tail.Next = newNode;
tail = newNode;
}
// don't forget
count++;
}
我想知道是否有一个属性可以强制发生operation
这样的事情?否则它会触发编译时错误消息。