我是 C# 的新手。只是玩弄它。不是为了真正的目的。
void makeOutput( int _param)
{
Console.WriteLine( _param.ToString());
}
//...
// Somewhere in a code
{
makeOutput( /* some not c# code for an example for what do I want */ function : int () { return 0; } );
}
是否可以使用真正的匿名函数(意味着返回结果)?
我不想使用代表,例如
// Somewhere in a code
{
Func<int> x = () => { return 0; };
makeOutput( x())
}
另外我不想更改方法参数类型,例如
void makeOutput( Func<int> _param)
{
}
这是非常普遍的决定。
一切正常。我只是明白我想要不可能的事情。我想声明匿名函数并在同一个地方执行它。注意:没有通用包装器的直接声明和直接调用。
// flash-like (as3) code /// DOES NOT COMPILE
makeOutput( (function : int(){ return 0; })() );