C# struct and Unity3d Vector3

本文介绍了C#中的new操作符如何用于struct类型的实例化,并解释了它与Java中的区别。通过Unity3d中的Vector3实例展示了struct类型属性返回副本的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The new operator is also used to invoke the constructor for value types. Value-type objects such as structs are created on the stack.

—— C# new operator


This is not like Java. In C#, you can new a struct fearlessly. It's not terribly wasteful because it's created on the stack, not the heap.

Feel free to use new in C# !


Unity3d: Vector3 Transform.position is a property and Vector3 is a struct type. So the get property returns a copy of Vector3.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值