当前位置:网站首页>C # introductory series (XIII) -- getting to know the structure for the first time
C # introductory series (XIII) -- getting to know the structure for the first time
2022-06-13 09:15:00 【InfoQ】
Concept
Definition
[public] struct Structure type name {
Member statement ;
}
- The member declaration describes the data member of this type ( Or data elements ) And a collection of other types of members .
- The number of members can be as many as you want , Determined by specific needs .
- Curly braces are the bounds of the member list .
public Member type List of member names ;
- for example , For the representation of coordinate point information, the following structure types can be established .
struct Ponit{
public int X; // Abscissa
public int Y; // Ordinate
}
Additional explanation
- struct Is a keyword that defines the structure type , Does not represent a data type .
- Only use struct Keyword defines the specific structure type before defining the corresponding variable , So it can't be used struct Keyword as the data type of the variable .
- Members of structure types can be either simple data types , It can also be of structure type , That is, the definition of structure can be nested . such as :
struct Ponit{
public int X; // Abscissa
public int Y; // Ordinate
}
struct Ponit_3{
public Ponit Pos_X_Y;
public int Z;
}
- C# The member type inside the structure is not allowed to be this structure . Such as :
struct Ponit{
public int X; // Abscissa
public int Y; // Ordinate
// This is a mistake Of
public Ponit pos;
}
- C# In addition to data members , It can also have function members .
- The biggest difference between structs and classes is that classes are reference types , And the structure is the value type . The structure is sealed 、 Not inheritable .
边栏推荐
猜你喜欢

Tutorial (5.0) 02 Management * fortiedr * Fortinet network security expert NSE 5

Use typescript to complete simple snake eating function

Mttr/mttf/mtbf diagram

turtle库的使用数字时钟模拟时钟动态显示

Installation of sonarqube code quality management platform (to be continued)
Drill down to protobuf - Introduction

20220524 how to install coppeliasim to disk D

Online debugging tool Arthas Foundation

攻防世界PWN play 条件竞争漏洞的利用

C language: minesweeping
随机推荐
20211108 能观能控,可稳可测
Installation of sonarqube code quality management platform (to be continued)
C language: recursive function to realize Hanoi Tower
BGP Federation +community
20211115 any n-order square matrix is similar to triangular matrix (upper triangle or lower triangle)
20220606 关于矩阵的Young不等式
20211108 det(AB)=det(A)det(B)
20211028 调节和跟踪
静态变量与一个类相关联,只要该类在内存中(只要您的应用程序终止,该变量就不存在)就可以使用。(堆本体,栈引用)
Solov2 source code analysis
Simulink的Variant Model和Variant Subsystem用法
Two good kids
20220524 如何把CoppeliaSim安装到D盘
类的加载概述
QML compilation specification
JS【中高级】部分的知识点我帮你们总结好了
Necessary and sufficient conditions for diagonalization of 20211115 matrix; The full rank matrix does not necessarily have n linearly independent eigenvectors; Symmetric matrices must be diagonalized
redis 模糊查询 批量删除
Longadder of the source code of JUC atomic accumulator
20211020 段院士全驱系统