像其他人一樣,你需要一個集合來循環播放。
我個人喜歡字典。
下面是一個例子,我認爲你可以根據自己的目的進行修改。
這將使您能夠「循環使用對象標籤」,但是如提到的HighCore,它可能不是「正確的方式」來完成您最終要完成的任何事情。
Image img1 = new Image();
Image img2 = new Image();
Image img3 = new Image();
img1.Tag = "tag1";
img2.Tag = "tag2";
img3.Tag = "tag3";
Dictionary<string, Image> ImgDictionary = new Dictionary<string, Image>();
ImgDictionary.Add(img1.Tag.ToString(), img1);
ImgDictionary.Add(img2.Tag.ToString(), img2);
ImgDictionary.Add(img3.Tag.ToString(), img3);
foreach (KeyValuePair<string, Image> i in ImgDictionary)
{
// do stuff with i.Value or i.Key
}
string tmp_TagName = "tag1";
if (ImgDictionary.ContainsKey(tmp_TagName))
{
Image ReturnImage;
ImgDictionary.TryGetValue(tmp_TagName, out ReturnImage);
// do something with your ReturnImage...
}
'圖像'不是一個集合,所以這是有道理的。老實說,整個用例聽起來很奇怪。你能否充實你想要完成的事情,這樣我們可以提出一個更好的方法? – BradleyDotNET 2014-09-12 18:36:33
錯誤信息告訴你到底發生了什麼錯誤。如果你不熟悉'GetEnumerator',那麼就直接google吧 – MethodMan 2014-09-12 18:39:26