2010-11-12 95 views

回答

4

是的。 delegate { return xyz; }和lambda x => x+1語法都可以返回值。

1

我也有這個問題,並寫了一個測試程序。答案是肯定的。

using System; 

public delegate int ReturnedDelegate(string s); 

class AnonymousDelegate 
{ 
    static void Main() 
    { 
     ReturnedDelegate len = delegate(string s) 
     { 
      return s.Length; 
     }; 
     Console.WriteLine(len("hello world")); 
    } 
}