任务:参数传递
来源:互联网 发布:大数据底层开发工程师 编辑:程序博客网 时间:2024/04/29 15:52
using System;using System.Threading;using System.Threading.Tasks;namespace TaskExample{class c4{static void Main(){var t1 = new Task<Tuple<int, int> > ( Fun2, Tuple.Create< int, int >( 16, 5 ) );t1.Start();Console.WriteLine( t1.Result );t1.Wait();Console.WriteLine( "result from task: {0} {1}", t1.Result.Item1, t1.Result.Item2 );string str = "Hello";var t2 = new Task<Tuple<int>>( Fun1, str );t2.Start();t2.Wait();Console.WriteLine( "result of t2 is {0}.", t2.Result.Item1 );}static Tuple< int, int > Fun2( object division ){Tuple< int, int > div = (Tuple<int, int > )division;int result = div.Item1 / div.Item2;int reminder = div.Item1 % div.Item2;Console.WriteLine( "task creates a result..." );return Tuple.Create< int, int >( result, reminder );}static Tuple<int> Fun1( object msg ){Console.WriteLine( msg );return Tuple.Create<int>(1);}}}
运行结果:
task creates a result...(3, 1)result from task: 3 1Helloresult of t2 is 1.
t1:传入2个参数,返回2个参数。
t2:传入1个参数,返回1个参数。返回值是一个时,也可以参考t1的方法。
不论是参数还是返回值,都可以是多个,具体都看Tuple。
- 任务:参数传递
- 第十七周任务:体会函数参数传递
- 多任务时的参数传递处理
- c# 多线程传递参数以及任务
- SSIS中执行SQL任务组件参数传递的问题
- 第十七周上机任务-项目1-体会函数参数传递
- 体会函数参数传递(第十七周上级任务)
- C++ 十七周任务-体会函数参数传递
- AsyncTask异步任务类以及如何给它传递参数
- 参数值的传递不是函数的任务!
- activiti 接收活动任务传递参数(九)
- 参数传递
- 参数传递
- 参数传递
- 传递参数
- 参数传递
- 参数传递
- 参数传递
- Mysql源代码级调试方法
- spring 声明式事务配置,抛出runtimeException异常不回滚
- Oracle优化总结
- cocos2d 步骤
- Oracle 修改表名 列名 字段类型 语句
- 任务:参数传递
- 算法导论 3.2-3
- python去掉字符串中的字母,只保留数字
- 金融e时代:数字化时代的金融变局
- icon font的理解,制作和使用
- Test SRM Level Three: LargestCircle, Brute Force
- json key value
- NGUI的工作总结(一)
- php的foreach,while,for的性能比较