【发布时间】:2017-10-10 11:46:39
【问题描述】:
public class Item{ some variables and methods }
public Item[] stash = new Item[50];
stash[a] = new Item();
stash[a].somevar = somevalue;
public Item it1 = stash[a];
stash[b] = new Item();
stash[b].somevar = someothervalue;
public Item it2 = stash[b];
我想只使用 it1 和 it2 交换 stash[a] 和 stash[b] 的内容strong> 因为发生在我无法再访问 a 和 b 值的不同代码块中。
我对 C# 的经验很少,所以我很难理解它如何处理类实例数组。
【问题讨论】:
-
所以你有
stash和it1和it2并且你想在stash中交换it1和it2? -
你不能交换你不知道的东西,在这种情况下你不知道索引
-
@Chris 是的,这就是我想做的。