Je suis un gars C# et j'ai obtenu cette logique en php à partir d'un site Web. Besoin de mettre en œuvre la même chose en C#.Aide à comprendre le code PHP en 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";
}
Dans la dernière ligne ci-dessus est une matrice 3 dimensions ou Hashtable? il semble que c'est une cause de hashtable [$ pkey] ['children'] [$ ckey] m'embête.
Quelqu'un peut-il convertir le code ci-dessus en C#? J'apprécierais vraiment.
Merci pour l'explication Konrad. Pouvez-vous m'aider à traduire en C#? Je ne suis pas un expert mais je peux essayer si l'exemple donné. – user342944
quelque chose comme ça? http://csharptutorial.com/blog/use-strongly-typed-generics-dictionary-data-structure-to-lookup-constants/ – user342944