当前位置:网站首页>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 .
边栏推荐
- The gbase 8A database does not support the DB2 function value (column_name, 0) cluster syntax
- i++与++i的区别:通俗易懂的讲述他们的区别
- Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026
- Talk about the design and implementation logic of payment process
- How to train mask r-cnn model with your own data
- [combinatorics] recursive equation (special solution example 1 Hannover tower complete solution process | special solution example 2 special solution processing when the characteristic root is 1)
- SQL injection database operation foundation
- PR second time
- The third day of writing C language by Yabo people
- Electronic Science and technology 20th autumn "Microcomputer Principle and application" online assignment 2 [standard answer]
猜你喜欢
国内如何购买Google Colab会员
Global and Chinese health care OEM and ODM market status survey and investment planning recommendations report 2022-2028
How to train mask r-cnn model with your own data
List的stream中Long对象与long判等问题记录
1146_ SiCp learning notes_ exponentiation
[combinatorics] recursive equation (summary of the solution process of recursive equation | homogeneous | double root | non-homogeneous | characteristic root is 1 | exponential form | the bottom is th
Play with fancy special effects. This AE super kit is for you
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
Getting started with deops
Leetcode Valentine's Day Special - looking for a single dog
随机推荐
Research on Swift
Five problems of database operation in commodity supermarket system
Global and Chinese health care OEM and ODM market status survey and investment planning recommendations report 2022-2028
Records of long objects and long judgments in the stream of list
QT学习日记9——对话框
Leetcode Valentine's Day Special - looking for a single dog
Cloud primordial weekly | CNCF released the 2021 cloud primordial development status report, which was released on istio 1.13
Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026
The difference between get and post
【RT-Thread】nxp rt10xx 设备驱动框架之--Audio搭建和使用
Managing multiple selections with MVVM - managing multiple selections with MVVM
Detailed explanation of common network attacks
Introduction to SolidWorks gear design software tool geartrax
Enterprise custom form engine solution (XI) -- form rule engine 1
Notes on problems -- watching videos on edge will make the screen green
Embedded-c language-7
i++与++i的区别:通俗易懂的讲述他们的区别
Leetcode540: a single element in an ordered array
远程办公工具分享|社区征文
Servlet specification Part II