Je créer un dictionnary a partir de ma classe "friend" qui possède comme key l'ID de mon ami.
Voici ma classe "chat":
Voici ma classe "friend":
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 public class Chat { public string name { get; set; } public string message { get; set; } }
Et voici ce a quoi je fais appel pour instancier le dictionnaire:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 public class Friends { public string Friend_id { get; set; } public string Name { get; set; } public string Message { get; set; } public string FriendAvatar { get; set; } public string Status { get; set; } public string Status_Image { get; set; } public List<Chat> chat_list { get; set; } }
Jusqu'à la rien d'incroyable et tout fonctionne correctement. La ou ca devient problematique c'est lorsque je souhaite ajouter un élément a ma liste chat_list de ma classe "friend".
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 public Dictionary<string, Friends> GetFriend(test.ArrayOfString friend_info_tab) { Dictionary<string, Friends> temp_friend = new Dictionary<string, Friends>(); int i = 1; int array_length; array_length = friend_info_tab.Count; if (array_length == 1) Error_Display("Array Length = 1", "No friends reported"); else if (array_length > 1) { while (i < array_length) { temp_friend.Add(friend_info_tab[i], new Friends() { Friend_guid = friend_info_tab[i], Name = friend_info_tab[i + 1], Message = friend_info_tab[i + 2], FriendAvatar = Get_avatar(friend_info_tab[i]), Status = "0", Status_Image = "URL", chat_list = new List<Chat>(), }); i = i + 3; } } return temp_friend;
Voici comment j'essayais de procéder:
En temps normal je sais ajouter, insérer et retirer des éléments d'une liste, mais dans ce cas précis je n'arrive vraiment pas a comprendre comment y parvenir. Je suis conscient que ca peut paraitre idiot comme question et je suis sur que la réponse est toute simple mais même en cherchant je n'ai pas trouver.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 friend_list[chat_friend_guid].chat_list.Add(new Chat() {name = "", message = ""});
Merci d'avance.
Partager