当前位置:网站首页>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 .
边栏推荐
- 诸神黄昏时代的对比学习
- Apache服务器访问日志access.log设置
- Web知识补充
- Rsyslog configuration and use tutorial
- Rsyslog配置及使用教程
- 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
- Besides, rsync+inotify realizes real-time backup of data
- WPF双滑块控件以及强制捕获鼠标事件焦点
- Database lock table? Don't panic, this article teaches you how to solve it
- 阿里云有奖体验:用PolarDB-X搭建一个高可用系统
猜你喜欢
随机推荐
Flet教程之 03 FilledButton基础入门(教程含源码)(教程含源码)
6 分钟看完 BGP 协议。
Using nsproxy to forward messages
使用 NSProxy 实现消息转发
CA:用于移动端的高效坐标注意力机制 | CVPR 2021
Configure WebDAV server on Apache
提高MySQL深分页查询效率的三种方案
[leetcode] 96 and 95 (how to calculate all legal BST)
HAProxy高可用解决方案
A data person understands and deepens the domain model
Using nsproxy to forward messages
高效!用虚拟用户搭建FTP工作环境
n++也不靠谱
Xue Jing, director of insight technology solutions: Federal learning helps secure the flow of data elements
FS4056 800mA充电ic 国产快充电源ic
C#/VB. Net to add text / image watermarks to PDF documents
Talk about the design and implementation logic of payment process
强化学习-学习笔记1 | 基础概念
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
go-zero微服务实战系列(九、极致优化秒杀性能)





![[leetcode] 96 and 95 (how to calculate all legal BST)](/img/d5/788c88064bce6a7c4499017908b3f2.jpg)


