开发者

C# code refactoring?

How to convert this code:

MYCLASS ebt = new 开发者_Python百科MYCLASS();
ebt.cbStruct = Marshal.SizeOf(ebt);

into this:

MYCLASS ebt = new MYCLASS(cbStruct = Marshal.SizeOf('What comes here?'));


modify the MYCLASS ctor,

public MYCLASS()
{
   cbStruct = Marshall.SizeOf(this);
}


Get the size of the type instead:

MYCLASS ebt = new MYCLASS { cbStruct = Marshal.SizeOf(typeof(MYCLASS)) };

Also note braces rather than parentheses to use initialiser syntax.


Use a MYCLASS constructor that takes a cbStruct parameter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜