概要
var t1 = new Task<int>(Fun, a);
int r = (int)t1.Result;
static int Fun(Object o) {
int a = (int)o;
return a*2;
}
代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Runtime.CompilerServices;
namespace ConsoleApp7
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello word");
int a = 8;
var t1 = new Task<int>(Fun, a);
t1.Start();
t1.Wait();
int r = (int)t1.Result;
Console.WriteLine(r);
Console.ReadKey();
}
static int Fun(Object o) {
int a = (int)o;
return a*2;
}
}
}
运行结果