开发者

public value struct in WinRT

Why "public value struct" can not have any method or constructor but "value struct" can? How to write structs li开发者_运维百科ke "Vector3" in WinRT component library and use it in another WinRT application?


When you declare a struct as "public", you're declaring it as a windows runtime structure. Structs in the windows runtime are value types. They cannot have methods (or constructors).

They are also marshaled by value which may not be what you want.

You probably would want to create a class instead of a struct.


Valuetypes/structs are mapped as "blocks" of memory much like the traditional C struct rather than the implementation that .Net has i.e.: which can contain fields and methods..

So the value types needs to only have fields in them or a constructor.

You will need to split the Vector3 into two parts, one with the data perhaps called Vector3Data with Vector3 having all the methods you need to manipulate it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜