当前位置:网站首页>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 .
边栏推荐
- Select 3 fcpx plug-ins. Come and see if you like them
- Electronic Science and technology 20th autumn "Microcomputer Principle and application" online assignment 2 [standard answer]
- Leetcode540: a single element in an ordered array
- Life perception 1
- A day's work list of an ordinary programmer
- 聊聊支付流程的设计与实现逻辑
- POM in idea XML graying solution
- i++与++i的区别:通俗易懂的讲述他们的区别
- STM32H7 HAL库SPI DMA发送一直处于busy的解决办法
- Kotlin的协程:上下文
猜你喜欢

Global and Chinese health care OEM and ODM market status survey and investment planning recommendations report 2022-2028
![[RT thread] NXP rt10xx device driver framework -- Audio construction and use](/img/85/32a83eaa4b7f5b30d4d7c4f4c32791.png)
[RT thread] NXP rt10xx device driver framework -- Audio construction and use

How to purchase Google colab members in China

SWM32系列教程4-端口映射及串口应用

Notes on problems -- watching videos on edge will make the screen green

Leetcode 108 converts an ordered array into a binary search tree -- recursive method

Research Report on competitive strategy Outlook Analysis and investment strategic planning of China's smart home equipment industry, 2022-2028
![[UE4] brush Arctic pack high quality Arctic terrain pack](/img/e7/bc86bd8450b0b2bdec8980a2aa1a10.jpg)
[UE4] brush Arctic pack high quality Arctic terrain pack

STM32实现74HC595控制

How to install PHP on Ubuntu 20.04
随机推荐
Basic grammar of interview (Part 2)
TensorBoard快速入门(Pytorch使用TensorBoard)
1164 Good in C
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
Research on Swift
University of Electronic Science and technology, accounting computerization, spring 20 final exam [standard answer]
Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
ES6类的继承
Vs2013 has blocked the installer, and ie10 needs to be installed
AcWing 3438. Number system conversion
Leetcode 108 converts an ordered array into a binary search tree -- recursive method
1146_ SiCp learning notes_ exponentiation
QT learning diary 9 - dialog box
Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
【RT-Thread】nxp rt10xx 设备驱动框架之--hwtimer搭建和使用
Hongmeng third training
MinGW compile boost library
Web-ui automated testing - the most complete element positioning method
毕业总结
[RT thread] NXP rt10xx device driver framework -- Audio construction and use