Class Test
{
Private Int I;
Private String S;
Public Test ( Int N1, String S1)
{
This . I = N1;
This . S = S1;
}
Public Void Withparameters ()
{
Console. writeline ( " Thread startup, parameter {0 },{ 1} " , I, S );
}
}
Class Program
{
Static Void Main ()
{
Thread th = New Thread (New Parameterizedthreadstart (withparameters )); // You can use parameterizedthreadstart to pass an object parameter. Object parameters can be converted to multiple parameters
Th. Start ( " Parameterizedthreadstart " );
Test T = New Test ( 123 , " Parameters " ); // The custom class can pass multiple parameters.
Thread Th1 = New Thread (T. withparameters );
Th1.start ();
Thread 2nd = New Thread () => withparameters ( " Lambda " )); // The Lambda anonymous method can pass multiple parameters.
Th2.start ();
Console. readkey ();
}
Static Void Withparameters ( Object OBJ)
{
String O = OBJ As String ;
If (! String . Isnullorempty (o ))
{
Console. writeline ( " Thread startup, parameter {0} " , O );
}
}
}