有人檢查我的代碼類,如果可能這樣做,我得到了類內的值。詳細如下檢查:類與數據結構參數類C#團結
classLogBarter.cs //使類
[System.Serializable]
public class classLogBarter {
public string DisplayName;
public string PlayerID;
public int CommentID;
public string Time;
public List<item> ItemBarter = new List<item>(); // Here is that possible ?
public classLogBarter (string playerid, string displayname, int commentid, string time, List<item> itembarter // Here how about this ?) {
PlayerID = playerid;
DisplayName = displayname;
CommentID = commentid;
Time = time;
itembarter = new List<item>(); // Is this correct ?
ItemBarter = itembarter; // Is this correct ?
}
public classLogBarter Clone() {
return new classLogBarter (PlayerID, DisplayName, CommentID, Time, ItemBarter);
}
public classLogBarter() {
}
}
LogBarter.cs //添加值到類// Asumption是BarterItem變量有1或2的值。
public List<classLogBarter> LogBarter = new List<classLogBarter>();
public List<item> BarterItem = new List<item>(); // Asumption that BarterItem Have 1 or 2 Value. Here now have BarterItem[0] and BarterItem[1]
LogBarter.Add(new classLogBarter(playerID,displayNames,1,times,BarterItem));
//向的debug.log顯示LogBarter值
for (int i = 0; i < LogBarter.Count; i++) {
for(int j = 0; j < LogBarter[i].ItemBarter.Count; j++) {
Debug.Log ("Player LogBarter : " + LogBarter [i].ItemBarter [j].itemName); // Here there is no value in here.
}
}
我要問什麼是爲什麼當LogBarter的debug.log [I] .ItemBarter [J] .itemName有沒有物品?
有什麼我想念的嗎?或者我只是在用paramater類創建類時犯了錯誤?
什麼意思是「假設有1或2個值」?爲什麼你認爲它有價值?你在某處添加它們嗎?如果這是你的所有代碼,你有什麼是準備添加項目的列表,但沒有項目。 – Everts
是的,我已經在LogBarter.Add之前添加它們。所以我假設BarterItem已經有了2個值。你現在明白了嗎? –
你能檢查課堂上課時我是如何放置課堂項目的嗎?這是對的還是不對? –