C# Как получить значение переменной С в основном потоке?
static void Main(string[] args)
{
Thread myThread = new Thread(new ThreadStart(count));
myThread.Start();
Console.WriteLine(C); // Как получить значение переменной С в основном потоке?
Console.ReadLine();
}
static void count()
{
int A = 1;
int B = 2;
int C = A + B;
}
Ответы (1 шт):
Автор решения: Leksor
→ Ссылка
static void Main(string[] args)
{
var c = 0;
var thread = new Thread(() => { c = Count(); });
thread.Start();
thread.Join();
Console.WriteLine(c.ToString());
Console.ReadLine();
}
public int Count()
{
int A = 1;
int B = 2;
return A + B;
}