18. Structs

Structs are similar to classes in that they represent data structures that
can contain data members and
function members. However, unlike classes, structs are value types and do
not require heap allocation. A
variable of a struct type directly contains the data of the struct, whereas
a variable of a class type contains a
reference to the data, the latter known as an object.
[Note: Structs are particularly useful for small data structures that have
value semantics. Complex numbers,
points in a coordinate system, or key-value pairs in a dictionary are all
good examples of structs. Key to
these data structures is that they have few data members, that they do not
require use of inheritance or
referential identity, and that they can be conveniently implemented using
value semantics where assignment
copies the value instead of the reference. end note]
As described in §11.1.3, the simple types provided by C#, such as int,
double, and bool, are, in fact, all
struct types. Just as these predefined types are structs, it is also
possible to use structs and operator
overloading to implement new ?primitive? types in the C# language. Two
examples of such types are given
at the end of this chapter (§18.4).
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值