, ref , . , Main One, Produce.
One . Produce .
, , , , . , _queue Main, .
. One ( " " ) , ref . queue = _queue;, ref .
A - Holder<T> class
, , Holder :
public class Holder<T> {
public T { get; set; }
}
One Holder<Queue<string>>. Main Holder<Queue<string>>. , One , Main.
, . , , . ? ? , , .
B -
. #, . , .
C -
Your own answer gave me an idea for a third possible solution. It is inherently very similar to the other two solutions. Instead of explaining it in English, let me show it in C #.
class One
{
Queue<string>[] queueArray;
public One(Queue<string>[] queueArray)
{
if (queueArray == null) throw new ArgumentNullException("queueArray");
if (queueArray.Length != 1) throw new ArgumentException("queueArray must have one and only one item");
this.queueArray = queueArray;
}
public void Produce()
{
queueArray[0] = new Queue<string>();
queueArray[0].Enqueue("one");
}
}
class Program
{
static void Main(string[] args)
{
var queueArray = new Queue<string>[] { new Queue<string>() };
One one = new One(queueArray);
one.Produce();
string value = queueArray[0].Dequeue();
}
}
source
share