Bonjour,
je cherche comment appeler une méthode générique à partir d'un thread. J'ai essayé avec cette exemple mais il m'affiche des erreurs.
avez-vous une idée comment appeler la méthode Affiche ?
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
28
29
30
31
32
33
34
35 class Program { static void Main(string[] args) { int i = 5; double d = 9.5; string s = "abcd"; Voiture v = new Voiture(); Thread newThread = new Thread(Affiche); newThread.Start(); Afficheur.Affiche(i); Afficheur.Affiche(d); Afficheur.Affiche(s); Afficheur.Affiche(v); } } public static class Afficheur { public static void Affiche<T>(T a) { Console.WriteLine("Afficheur d'objet :"); Console.WriteLine("\tType : " + a.GetType()); Console.WriteLine("\tReprésentation : " + a.ToString()); } } public class Voiture { public string Couleur { get; set; } public string Marque { get; set; } public int Vitesse { get; set; } }
Partager