我有另一個問題轉換數組從PHP到C#。C#轉換幫助和PHP
public $array = array(103 => array('', ''), 102 => array('', ''), 101 => array('', '', ''), 100 => array('', '', '', ''));
這是我有:
public Dictionary<int, List<string>> waddlesById = new Dictionary<int, List<string>>();
問題是,每當我這樣做:
sizeof($this->array[$waddleId]) - 1
,等於-1,但是如果在C#中做到這一點:
waddlesById[waddleId].Count - 1
等於0. 這是我的構造函數:
string maxSeats = String.Empty;
foreach (int waddleId in sledRacing)
{
switch (waddleId)
{
case 103:
case 102:
maxSeats = ",";
break;
case 101:
maxSeats = ",,";
break;
case 100:
maxSeats = ",,,";
break;
}
if (waddlesById.ContainsKey(waddleId))
{
waddlesById[waddleId].Add(maxSeats);
}
else
{
List<string> newInner = new List<string>();
newInner.Add(maxSeats);
waddlesById.Add(waddleId, newInner);
}
}
任何幫助表示讚賞
你有沒有考慮重新設計你的代碼,而不是試圖將其直接移植到C#? –
@SimonWhitehead我還沒有,沒有必要去做 – user3771693
@ user3771693,那麼你不得不這樣做,因爲'array'與'List'不一樣...... – developerwjk