|
using System;
using System.Collections.Generic;
class They {
public struct AAA {
public int value;
}
private List<AAA> container;
public They() {
container = new List<AAA>();
for ( int i = 0; i < 10; ++i ) {
AAA item = new AAA();
item.value = i;
container.Add(item);
}
}
public List<AAA> getValues() {
return new List<AAA>(container); // ←やりたかったのはコレ?
}
public void printValues() {
foreach ( AAA item in container ) {
Console.Write("{0} ", item.value);
}
Console.WriteLine();
}
}
class We {
private List<They.AAA> container;
public We(They t) {
// Theyからもらって
container = t.getValues();
// 確認のためいくつか書き換え
for ( int i = 0; i < container.Count; i += 2 ) {
They.AAA item = new They.AAA();
item.value = -i;
container[i] = item;
}
}
public void printValues() {
foreach ( They.AAA item in container ) {
Console.Write("{0} ", item.value);
}
Console.WriteLine();
}
public static void Main() {
They t = new They();
We w = new We(t);
t.printValues();
w.printValues();
}
}
|