我是一個C#人,並從一個網站得到了這個邏輯到PHP。需要在C#中實現相同的功能。幫助理解PHP代碼到C#
$items = array();
while($row = mysql_fetch_assoc($query))
{
//parent id
$pkey = $row['parent_id'];
//child id
$ckey = $row['category_id'];
//store this
$items[$pkey]['children'][$ckey] = $row['categoryname'];
}
//create our list
$first = true;
//create our list
createList($items, $first);
function createList($array, $first)
{
//we need access to the original array
global $items;
//first is a flag on whether or not this is the first item in the array
//we use this flag so that you don't need to initially call the function using createList($array[0]['children'])
if($first){
$array = $array[0]['children'];
}
echo "<ol>\n";
foreach($array as $key => $value){
echo "<li>{$value}";
//if this item does have children, display them
if(isset($items[$key]['children'])){
echo "\n";
createList($items[$key]['children'], false); //set $first to false!
}
echo "</li>\n";
}
echo "</ol>\n";
}
在上述最後一行是一個3維陣列或哈希表?它看起來像一個哈希表的原因[$ pkey] ['children'] [$ ckey]正在竊聽我..
任何人都可以在C#中轉換上述代碼?我真的很感激。
感謝您的解釋Konrad。你能幫我翻譯C#嗎?我不是專家,但我可以嘗試給出的例子。 – user342944 2010-05-17 11:06:10
這樣的事情? http://csharptutorial.com/blog/use-strongly-typed-generics-dictionary-data-structure-to-lookup-constants/ – user342944 2010-05-17 11:10:20