c#-多线程-任务-返回值-组合类型

1.概要

var t1 = new Task<Tuple<int, int>>(Fun, a);

static Tuple<int,int> Fun(Object o) {
            int a = (int)o;
            return Tuple.Create<int, int>(4*a, 5*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<Tuple<int, int>>(Fun, a);
            t1.Start();
            t1.Wait();
            Console.WriteLine("{0},{1}", t1.Result.Item1, t1.Result.Item2);
            Console.ReadKey();
        }
        static Tuple<int,int> Fun(Object o) {
            int a = (int)o;
            return Tuple.Create<int, int>(4*a, 5*a);
        }

        
    }
}

3.运行结果 

c#-多线程-任务-返回值-组合类型

上一篇:Python Sequence:序列,列表list、元组tuple


下一篇:数据类型