当前位置:网站首页>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 .
边栏推荐
- After the game starts, you will be prompted to install HMS core. Click Cancel, and you will not be prompted to install HMS core again (initialization failure returns 907135003)
- 【云原生 | Kubernetes篇】深入了解Ingress(十二)
- CVPR 2022 | transfusion: Lidar camera fusion for 3D target detection with transformer
- N++ is not reliable
- After the game starts, you will be prompted to install HMS core. Click Cancel, and you will not be prompted to install HMS core again (initialization failure returns 907135003)
- CANN算子:利用迭代器高效实现Tensor数据切割分块处理
- 从0到1建设智能灰度数据体系:以vivo游戏中心为例
- Runc hang causes the kubernetes node notready
- Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
- runc hang 导致 Kubernetes 节点 NotReady
猜你喜欢
Commvault 和 Oracle 合作,在 Oracle 云上提供 Metallic数据管理即服务
After installing vscode, the program runs (an include error is detected, please update the includepath, which has been solved for this translation unit (waveform curve is disabled) and (the source fil
Etcd 存储,Watch 以及过期机制
Etcd storage, watch and expiration mechanism
Read the BGP agreement in 6 minutes.
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
高质量软件架构的唯一核心指标
实时云交互如何助力教育行业发展
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
Meituan Ali's Application Practice on multimodal recall
随机推荐
Valentine's Day confession code
C#/VB. Net to add text / image watermarks to PDF documents
go-zero微服务实战系列(九、极致优化秒杀性能)
8个扩展子包!RecBole推出2.0!
MySQL three-level distribution agent relationship storage
Use fail2ban to prevent password attempts
The old-fashioned synchronized lock optimization will make it clear to you at once!
Using scrcpy projection
Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
诸神黄昏时代的对比学习
JVM系列——栈与堆、方法区day1-2
从0到1建设智能灰度数据体系:以vivo游戏中心为例
Detailed explanation of mt4api documentary and foreign exchange API documentary interfaces
How real-time cloud interaction helps the development of education industry
Commvault 和 Oracle 合作,在 Oracle 云上提供 Metallic数据管理即服务
AI 绘画极简教程
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
Solution: how to delete the information of Jack in two tables with delete in one statement in Oracle
ISO 27001 Information Security Management System Certification
2022年中国移动阅读市场年度综合分析