Net PerfectDev

Net PerfectDev

  • 1.6k
  • 146
  • 4.7k

call Generic method from a thread

Dec 16 2021 8:50 AM

Hello,
I'm looking for how to call a generic method from a thread. I have tried with this example but it shows me errors.

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; }
    }

do you have any idea how to call the poster method?


Answers (1)