Home > Article > Backend Development > C# program that passes parameters to threads
To use threads, add the following namespace in your code -
using System.Threading;
First you need to create a new thread in C# -
Thread thread = new Thread(threadDemo);
Above, threadDemo is our thread function.
Now pass the parameters to the thread-
thread.Start(str);
The parameters set above are-
String str = "Hello World!";
Let us see passing the parameters in C# Give the complete code to the thread.
Real-time demonstration p>
using System; using System.Threading; namespace Sample { class Demo { static void Main(string[] args) { String str = "Hello World!"; // new thread Thread thread = new Thread(threadDemo); // passing parameter thread.Start(str); } static void threadDemo(object str) { Console.WriteLine("Value passed to the thread: "+str); } } }
Value passed to the thread: Hello World!
The above is the detailed content of C# program that passes parameters to threads. For more information, please follow other related articles on the PHP Chinese website!