C# で ref キーワードを使用して、デリゲート関数に渡されるクラス変数を変更しようとしています。親とその 2 つの子のコンテナーに格納されている値をデリゲート関数で変更できるようにしたいと考えています。現在起こっていることは、デリゲート関数は親を変更できますが (container[parent] に直接参照を渡すため)、子は変更できません。最初にそれらを処理して、leftChild と rightChild への参照を渡す必要があるためです。
デリゲート関数がコンテナに格納されている値を変更できるように、leftChild をコンテナ [leftChildIndex] への参照にすることは可能ですか? (右の子も同様)
private void traversePostOrder(Modify operation, int parentIndex) { if (parentIndex < size) { int leftChildIndex = getLeftChildIndex(parentIndex); int rightChildIndex = getRightChildIndex(parentIndex); T parent = container[parentIndex]; T leftChild = default(T); T rightChild = default(T); Library.Diagnostics.Message.logMessage("P: " + parent, 2); if (leftChildIndex < container.Length) { traversePostOrder(operation, leftChildIndex); leftChild = container[leftChildIndex]; } if (rightChildIndex < container.Length) { traversePostOrder(operation, rightChildIndex); rightChild = container[rightChildIndex]; } operation(ref container[parentIndex], ref leftChild, ref rightChild); } }