当前位置:网站首页>Design limitations of structure type (struct)
Design limitations of structure type (struct)
2022-07-03 17:45:00 【Extremely unconstitutional】
Structure Less used in the development process , If it is C# call C++ The related functions of may pass parameters with the help of structures , Understand the relevant knowledge of structure , It helps us to better use the structure .
One 、 Design structure (struct) Type , Have and classes (class) Functions of the same type , But there are the following exceptions :
- You cannot declare a parameterless constructor . Each structure type already provides an implicit parameterless constructor , This constructor generates the default value of the type . Remarks from C# 10 Start , You can declare a parameterless constructor in a structure type . For more information , See the parameterless constructor and field initializer section .
- You cannot initialize instance fields or properties when they are declared . however , Static or constant fields or static attributes can be initialized in their declarations . Remarks from C# 10 Start , You can initialize instance fields or attributes when they are declared . For more information , See the parameterless constructor and field initializer section .
- The constructor of a structure type must initialize all instance fields of that type .
- Structure types cannot inherit from other classes or structure types , Nor can it be used as the basic type of a class . however , Structure types can implement interfaces .
- Finalizers cannot be declared in a structure type .
Two 、 Structure (struct) With C# The version upgrade is also iterating continuously .
- from C# 7.2 Start , have access to readonly Modifier to declare the structure type as immutable .
- from C# 7.2 Start , It can be used in the declaration of structure type ref Modifier .
- stay C# 8.0 And later , This means that instance members other than constructors are implicit readonly.
- from C# 8.0 Start , One time can be defined ref structure .
- from C# 8.0 Start , You can also use readonly Modifier declares that instance members will not modify the state of the structure .
- stay C# 9.0 And later , Can be readonly Modifier applied to have init Accessor properties or indexers .
- from C# 10 Start , have access to with Expression to generate a copy of the structure type instance that modifies the specified properties and fields .
- from C# 10 Start , You can declare a parameterless constructor in a structure type .
- from C# 10 Start , You can initialize instance fields or attributes when they are declared .
边栏推荐
- [RT thread] NXP rt10xx device driver framework -- Audio construction and use
- Draw some simple graphics with MFC
- 【RT-Thread】nxp rt10xx 设备驱动框架之--hwtimer搭建和使用
- Create a new file from templates with bash script - create new file from templates with bash script
- Golang unit test, mock test and benchmark test
- The gbase 8A database does not support the DB2 function value (column_name, 0) cluster syntax
- SQL injection database operation foundation
- Embedded-c language-7
- 鸿蒙第四次培训
- 问题随记 —— 在 edge 上看视频会绿屏
猜你喜欢
Tensorboard quick start (pytoch uses tensorboard)
Embedded-c language-7
一入“远程”终不悔,几人欢喜几人愁。| 社区征文
vs2013已阻止安装程序,需安装IE10
Five problems of database operation in commodity supermarket system
SQL injection database operation foundation
鸿蒙第四次培训
QT adjust win screen brightness and sound size
Cloud primordial weekly | CNCF released the 2021 cloud primordial development status report, which was released on istio 1.13
Baiwen.com 7 days Internet of things smart home learning experience punch in the next day
随机推荐
Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
[combinatorics] recursive equation (the non-homogeneous part is an exponential function and the bottom is the characteristic root | example of finding a special solution)
Kubernetes resource object introduction and common commands (4)
数学公式(测试)
Five problems of database operation in commodity supermarket system
vs2013已阻止安装程序,需安装IE10
POM in idea XML graying solution
2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
RDS数据库的监测页面在哪看?
The gbase 8A database does not support the DB2 function value (column_name, 0) cluster syntax
How to train mask r-cnn model with your own data
Qt调节Win屏幕亮度和声音大小
List的stream中Long对象与long判等问题记录
Create a new file from templates with bash script - create new file from templates with bash script
IntelliJ 2021.3 short command line when running applications
STM32实现74HC595控制
First day of rhcsa study
Deops入门
Golang unit test, mock test and benchmark test
Research on Swift