faire un tableau de "KeyValuePair<string, int>"
salut,
j'essaye de faire des graphique en wpf, j'y arrive très bien en faisant ceci:
Code:
1 2 3 4 5 6
| chart.DataContext = new KeyValuePair<string, int>[] {
new KeyValuePair<string, int>("truc", 30),
new KeyValuePair<string, int>("machin", 25),
new KeyValuePair<string, int>("bazar", 5)
}; |
l'ennui c'est que je ne sais pas d'avance ce qu'il y aura dedans. J'ai donc essayé:
Code:
1 2 3 4 5 6
|
object[] test = new KeyValuePair<string, int>[nombreElement];//l'erreur
test[0] = new KeyValuePair<string, int>("truc", 30);
chart.DataContext = test; |
mais je ne parvient pas a faire mon tableau, j'ai le message d'erreur:
Citation:
Cannot apply indexing with [] to an expression of type 'System.Collections.Generic.KeyValuePair<string,int>'
Je comprend ou est l'erreur mais je ne sais pas comment la résoudre :cry: