我是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; } );
}
Run Code Online (Sandbox Code Playgroud)
是否可以使用REAL匿名函数(意味着返回结果)?
我不想使用像这样的代表
// Somewhere in a code
{
Func<int> x = () => { return 0; };
makeOutput( x())
}
Run Code Online (Sandbox Code Playgroud)
另外我不想改变方法参数类型,如
void makeOutput( Func<int> _param)
{
}
Run Code Online (Sandbox Code Playgroud)
这是非常普遍的决定.
一切正常.我只是明白我想要不可能的东西.我想声明匿名函数并在同一个地方执行它.注意:DIRECT声明和DIRECT调用没有通用包装.
// flash-like (as3) code /// DOES NOT COMPILE
makeOutput( (function …Run Code Online (Sandbox Code Playgroud) 我真的很困惑.
// initial class
type
TTestClass =
class( TInterfacedObject)
end;
{...}
// test procedure
procedure testMF();
var c1, c2 : TTestClass;
begin
c1 := TTestClass.Create(); // create, addref
c2 := c1; // addref
c1 := nil; // refcount - 1
MessageBox( 0, pchar( inttostr( c2.refcount)), '', 0); // just to see the value
end;
Run Code Online (Sandbox Code Playgroud)
它应该显示1,但它显示0.无论我们将执行多少分配,值都不会改变!为什么不?
// interface
iccItem =
class
ID : String;
DATA : Variant;
constructor Create( _id : String; _data : Variant);
end;
iccDynamicObject =
class
private
FItems : TList;
function locate( _id : String) : iccItem;
public
constructor Create();
destructor Destroy(); override;
public
procedure define( _id : String; _dta : Variant);
//function get( _ndx : DWORD) : Variant; overload;// link to original data
function get( _id : String) : Variant; overload;
public
property Items[_id : String] : Variant read get write define; …Run Code Online (Sandbox Code Playgroud)