首页 > Windows开发 > 详细

C# 委托 Action Func

时间:2015-04-29 13:04:41      阅读:274      评论:0      收藏:0      [点我收藏+]

Action<T> : 传递参数,只进不出,所以方法为void

Func<in T, out Tv> : 传递参数,有进有出,所以传递的方法要return

 

 

using System;
using System.Collections.Generic;
using System.Linq;

namespace rooxml
{

    public class main
    {
        public delegate void fucA(string s);
        public static void Main ()
        {
            Action<string> ii = (string str) => {
                Console.WriteLine(str);
            };
            new A().bb(ii);

            fucA f = new A().aa;  
            f("777");  //委托直接调用
            //new A ().bb (new A().aa);

            Console.WriteLine(
            new A ().cc ((int i)=>{
                return (i*i).ToString();
            })
            );

        }
    }

    class A{
        public A(){ }

        public void aa(string s){
            Console.WriteLine (s+"666");
        }

        public void bb(Action<string> h){
            h ("555");
        }


        public string cc(Func<int, string> c){
            return c(7);
        }
            
    }
}

 

https://msdn.microsoft.com/zh-cn/library/bb549151.aspx

C# 委托 Action Func

原文:http://www.cnblogs.com/nnnnn/p/4465525.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!