LonghronShen
本帖最后由

本帖最后由 LonghronShen 于 2012-4-20 21:30 编辑

先来一份VB.NET的投机取巧解法

[mw_shl_code=vbnet,true]Namespace HelloWorld

Module Main

Public Class FuncEx(Of TArg, TResult)

Private m_function As Func(Of TArg, TResult)

Default Public ReadOnly Property [Function](ByVal x As TArg) As FuncEx(Of TArg, TResult)

Get

Return New FuncEx(Of TArg, TResult)(Me.m_function, Me.m_function(x))

End Get

End Property

Public Property LastResult() As TResult

Public Sub New(ByVal f As Func(Of TArg, TResult), Optional ByVal lr As TResult = Nothing)

Me.m_function = f

Me.LastResult = lr

End Sub

Public Overrides Function ToString() As String

Return Me.LastResult.ToString()

End Function

End Class

Public Function add(ByVal x As Object) As FuncEx(Of Object, Object)

Static c As Object = 0

c = c + x

Return New FuncEx(Of Object, Object)(

Function(y As Object)

Return add(y)

End Function, c)

End Function

Sub Main()

Console.WriteLine(add(2)(3))

Console.ReadKey(False)

End Sub

End Module

End Namespace[/mw_shl_code]