当前位置:网站首页>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 .
边栏推荐
- CA:用于移动端的高效坐标注意力机制 | CVPR 2021
- 使用 NSProxy 实现消息转发
- n++也不靠谱
- Simple understanding of binary search
- Two dimensional code coding theory
- Three schemes to improve the efficiency of MySQL deep paging query
- Golang sets the small details of goproxy proxy proxy, which is applicable to go module download timeout and Alibaba cloud image go module download timeout
- CANN算子:利用迭代器高效实现Tensor数据切割分块处理
- 求解:在oracle中如何用一条语句用delete删除两个表中jack的信息
- Database lock table? Don't panic, this article teaches you how to solve it
猜你喜欢
Reinforcement learning - learning notes 1 | basic concepts
上汽大通MAXUS正式发布全新品牌“MIFA”,旗舰产品MIFA 9正式亮相!
PostgreSQL 9.1 soaring Road
Three schemes to improve the efficiency of MySQL deep paging query
Etcd storage, watch and expiration mechanism
C#/VB. Net to add text / image watermarks to PDF documents
Commvault 和 Oracle 合作,在 Oracle 云上提供 Metallic数据管理即服务
聊聊支付流程的设计与实现逻辑
Meituan Ali's Application Practice on multimodal recall
AI painting minimalist tutorial
随机推荐
Besides, rsync+inotify realizes real-time backup of data
洞见科技解决方案总监薛婧:联邦学习助力数据要素安全流通
Using nsproxy to forward messages
Solution: how to delete the information of Jack in two tables with delete in one statement in Oracle
WPF double slider control and forced capture of mouse event focus
It is six orders of magnitude faster than the quantum chemical method. An adiabatic artificial neural network method based on adiabatic state can accelerate the simulation of dual nitrogen benzene der
When MDK uses precompiler in header file, ifdef is invalid
Is the outdoor LED screen waterproof?
Samsung's mass production of 3nm products has attracted the attention of Taiwan media: whether it can improve the input-output rate in the short term is the key to compete with TSMC
Node の MongoDB 安装
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
Apache server access log access Log settings
WPF双滑块控件以及强制捕获鼠标事件焦点
请问大佬们有遇到这个情况吗,cdc 1.4 连接MySQL 5.7 无法使用 timestamp
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)
从0到1建设智能灰度数据体系:以vivo游戏中心为例
【AI系统前沿动态第40期】Hinton:我的深度学习生涯与研究心法;Google辟谣放弃TensorFlow;封神框架正式开源
强化学习-学习笔记1 | 基础概念
AI 绘画极简教程
CTF competition problem solution STM32 reverse introduction