当前位置:网站首页>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 .
边栏推荐
- Comparison of kotlin collaboration + retro build network request schemes
- link preload prefetch
- Getting started with deops
- [combinatorics] recursive equation (case where the non-homogeneous part is exponential | example where the non-homogeneous part is exponential)
- [combinatorics] recursive equation (solution of linear non-homogeneous recursive equation with constant coefficients | standard form and general solution of recursive equation | proof of general solut
- The difference between get and post
- TensorBoard快速入门(Pytorch使用TensorBoard)
- ArrayList analysis 3: delete elements
- [RT thread] NXP rt10xx device driver framework -- Audio construction and use
- 国内如何购买Google Colab会员
猜你喜欢

SQL injection database operation foundation

互聯網醫院HIS管理平臺源碼,在線問診,預約掛號 智慧醫院小程序源碼
![[RT thread] NXP rt10xx device driver framework -- pin construction and use](/img/75/b4f034bfe49409f76e7fd92758804e.png)
[RT thread] NXP rt10xx device driver framework -- pin construction and use

Qt调节Win屏幕亮度和声音大小

面试官:值为 nil 为什么不等于 nil ?

Five problems of database operation in commodity supermarket system

Research on Swift

MySQL grouping query

一入“远程”终不悔,几人欢喜几人愁。| 社区征文

How to deploy applications on kubernetes cluster
随机推荐
Basic grammar of interview (Part 2)
自动渗透测试工具核心功能简述
Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026
WEB-UI自动化测试-最全元素定位方法
Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
[mathematical logic] equivalent calculus and reasoning calculus of predicate logic (individual word | predicate | quantifier | predicate logic formula | two basic formulas | proposition symbolization
TensorBoard快速入门(Pytorch使用TensorBoard)
Luogu: p1155 [noip2008 improvement group] double stack sorting (bipartite graph, simulation)
Global and Chinese health care OEM and ODM market status survey and investment planning recommendations report 2022-2028
Hongmeng third training
Examination questions for the assignment of selected readings of British and American Literature in the course examination of Fujian Normal University in February 2022
ES6类的继承
[RT thread] NXP rt10xx device driver framework -- Audio construction and use
Research on Swift
Records of long objects and long judgments in the stream of list
毕业总结
How to install PHP on Ubuntu 20.04
Internet Hospital his Management Platform source, online Inquiry, appointment Registration Smart Hospital Small program source
Inheritance of ES6 class
Luogu: p2685 [tjoi2012] Bridge