Interview question: How many total threads are there in below C# multithreading program?

static void Main(string[] args)
    {       
        Thread T1 = new Thread(foo);
        Thread T2 = new Thread(foo);
       
        T1.Start();
        T2.Start();
    }
   
    static void foo()
    {
        // some operation
    }

Answer: Total 3 threads are there in the above C# program.

We can see 2 child threads T1 and T2 and another 3rd thread is a main process itself because a process is also known as a thread. Hence, total thread count is 3 in the program.

NOTES:

In case, you need complete C# thread example, follow another interview questions that is how to create threads in C# .

Related Posts