完整程序见链接:http://www.javaeye.com/post/325759 (主题: 用C# 3.0 写了个IoC类 )看了一篇题为“主题: 用C# 3.0 写了个IoC类 ”的帖子,发觉有几个不明白的地方。public class SingleComponentService:IComponentService   
    {   
        private Func 
        private MicroContainer container;   
   
        public SingleComponentService(MicroContainer container,Func 
        {   
            this.container = container;   
            this.registerFunction = registerFunction;   
        }   
  
        #region IComponentService Members   
   
        public T GetComponent()   
        {   
            return (T)this.registerFunction(this.container);   
        }   
  
        #endregion   
    }   这一段,红字部分的那个“Func” 是什么?container.Register("FirstClass", c => new FirstClass()); 这一句里面,红色部分的“C =〉”是什么?

解决方案 »

  1.   

    Func的作用相当于C# 2.0的委托,C=>是lamda表达式,给你个示例:using System;
    using System.Collections.Generic;
    using System.Linq;namespace SayHello
    {
        class SayHello
        {
            static void Main(string[] args)
            {
                Func<string, string> ShowName = name => name.Equals("PLMM") ? name+",you are a pretty girl,may i make friend with you?":"hello,"+name;  
                List<string> names = new List<string> { "world", "Microsoft", "csdn", "PLMM" };
                foreach (var expression in names.Select(ShowName))
                {
                    Console.WriteLine(expression);
                }
            }
        }
    }Func主要使用场合是在linq查询中