开发者

C# code refactoring?

开发者 https://www.devze.com 2022-12-15 04:57 出处:网络
How to convert this code: MYCLASS ebt = new 开发者_Python百科MYCLASS(); ebt.cbStruct = Marshal.SizeOf(ebt);

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

精彩评论

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