当前位置:网站首页>C foundation in-depth study I
C foundation in-depth study I
2022-07-04 13:41:00 【Hua Weiyun】
C# Basic in-depth learning 01
Value type , Reference type
Data of value type is stored in the stack of memory , Data of reference type is stored in the heap of memory , The memory unit only stores the address of the object in the heap .
Value type variables directly store the actual data , Variables of reference type store the address of data , That is, the reference to the object .
Value type variables store the value of a variable directly on the stack , Reference type variables store the address of the actual data on the stack , The actual data is stored in the heap .
The value type represents the actual data , The reference type represents a pointer or reference to data stored in the memory heap .
Array
Array Attributes of a class
The following table lists them Array Some of the most commonly used properties in the class :
Serial number | attribute & describe |
---|---|
1 | IsFixedSize Get a value , This value indicates whether the array has a fixed size . |
2 | IsReadOnly Get a value , This value indicates whether the array is read-only . |
3 | Length Get one 32 An integer , This value represents the total number of elements in the array of all dimensions . |
4 | LongLength Get one 64 An integer , This value represents the total number of elements in the array of all dimensions . |
5 | Rank Get the rank of the array ( dimension ). |
If you need to know Array A complete list of properties of the class , See Microsoft's C# file .
Array Class method
The following table lists them Array Some of the most commonly used methods in classes :
Serial number | Method & describe |
---|---|
1 | Clear Depending on the type of element , Set the element of a range in the array to zero 、 by false Or for null. |
2 | Copy(Array, Array, Int32) Starting from the first element of the array, copy the elements of a range to the first element position of another array . The length consists of a 32 Bit integers specify . |
3 | CopyTo(Array, Int32) Copies all elements from the current one-dimensional array to the specified index position of a specified one-dimensional array . The index consists of a 32 Bit integers specify . |
4 | GetLength Get one 32 An integer , This value represents the total number of elements in the array of the specified dimension . |
5 | GetLongLength Get one 64 An integer , This value represents the total number of elements in the array of the specified dimension . |
6 | GetLowerBound Gets the lower bound of the specified dimension in the array . |
7 | GetType Gets the type of the current instance . From object (Object) Inherit . |
8 | GetUpperBound Gets the upper bound of the specified dimension in the array . |
9 | GetValue(Int32) Gets the value of a specified position in a one-dimensional array . The index consists of a 32 Bit integers specify . |
10 | IndexOf(Array, Object) Search for the specified object , Returns the first occurrence of the index in the entire one-dimensional array . |
11 | Reverse(Array) Reverse the order of elements in an entire one-dimensional array . |
12 | SetValue(Object, Int32) Sets the value of the element at the specified position in the one-dimensional array . The index consists of a 32 Bit integers specify . |
13 | Sort(Array) Use the... Of each element of the array IComparable Implement to sort the elements of the entire one-dimensional array . |
14 | ToString Returns a string representing the current object . From object (Object) Inherit . |
params keyword
When using arrays as formal parameters ,C# Provides params keyword , When calling a method that takes an array as a parameter , You can pass array arguments , You can also pass a set of array elements .params The format used is :
public Return type Method name ( params Type the name [] Array name )
Structure (Struct)
stay C# in , A structure is a value type data structure . It enables a single variable to store related data of various data types .struct Keyword is used to create a structure .
Structural characteristics
You have used a simple name Books Structure . stay C# The structure in is different from the traditional C or C++ The structure in is different .C# The structure in has the following characteristics :
- The structure can have methods 、 Field 、 Indexes 、 attribute 、 Operators, methods, and events .
- Structure defines a constructor , But you can't define destructors . however , You cannot define a parameterless constructor for a structure . Parameter free constructor ( Default ) Is automatically defined , And cannot be changed .
- Different from class , Structure cannot inherit other structures or classes .
- Structure cannot be used as the infrastructure of other structures or classes .
- Structure can implement one or more interfaces .
- Structure member cannot be specified as abstract、virtual or protected.
- When you use New When the operator creates a structure object , The appropriate constructor will be called to create the structure . Different from class , The structure may not use New Operators can be instantiated .
- If not used New The operator , Only after all fields have been initialized , The field is assigned , Objects are used .
class vs structure
Classes and structures have the following basic differences :
- Class is a reference type , A structure is a value type .
- Structure does not support inheritance .
- Structure cannot declare a default constructor .
- In the constructor of a struct , All fields of the structure must be assigned , Class constructor has no such restriction .
- A field declared in a structure cannot be given an initial value , Classes can be .
边栏推荐
- WPF double slider control and forced capture of mouse event focus
- MDK在头文件中使用预编译器时,#ifdef 无效的问题
- Detailed explanation of mt4api documentary and foreign exchange API documentary interfaces
- Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
- 【云原生 | Kubernetes篇】深入了解Ingress(十二)
- 游戏启动后提示安装HMS Core,点击取消,未再次提示安装HMS Core(初始化失败返回907135003)
- C#基础深入学习一
- Apache server access log access Log settings
- jsonp
- 实时云交互如何助力教育行业发展
猜你喜欢
PostgreSQL 9.1 飞升之路
8 expansion sub packages! Recbole launches 2.0!
聊聊支付流程的设计与实现逻辑
光环效应——谁说头上有光的就算英雄
Dry goods sorting! How about the development trend of ERP in the manufacturing industry? It's enough to read this article
诸神黄昏时代的对比学习
How real-time cloud interaction helps the development of education industry
高质量软件架构的唯一核心指标
洞见科技解决方案总监薛婧:联邦学习助力数据要素安全流通
A taste of node JS (V), detailed explanation of express module
随机推荐
c#数组补充
诸神黄昏时代的对比学习
Commvault 和 Oracle 合作,在 Oracle 云上提供 Metallic数据管理即服务
Backgroundworker usage example
XML入门三
Annual comprehensive analysis of China's mobile reading market in 2022
SQL statement syntax error in test SQL statement deletion in eclipse linked database
Iptables foundation and Samba configuration examples
AI 绘画极简教程
The old-fashioned synchronized lock optimization will make it clear to you at once!
A taste of node JS (V), detailed explanation of express module
Optional values and functions of the itemized contenttype parameter in the request header
游戏启动后提示安装HMS Core,点击取消,未再次提示安装HMS Core(初始化失败返回907135003)
【AI系统前沿动态第40期】Hinton:我的深度学习生涯与研究心法;Google辟谣放弃TensorFlow;封神框架正式开源
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
CVPR 2022 | TransFusion:用Transformer进行3D目标检测的激光雷达-相机融合
WPF双滑块控件以及强制捕获鼠标事件焦点
Etcd storage, watch and expiration mechanism
Comparative study of the gods in the twilight Era
Apache服务器访问日志access.log设置