当前位置:网站首页>C # basic 3-value type and reference type, packing and unpacking
C # basic 3-value type and reference type, packing and unpacking
2022-07-28 20:54:00 【W.C.Zeng】
Recommend learning B The station is looking for teacher liutiemanganese C# Getting started video
type
C# Is a strongly typed static language , When declaring variables, you need to determine the type of variables , The program runs after being compiled by the compiler
type To determine the ** 1. The amount of space the variable occupies in memory **, And then determined ** 2. Value range of variable **, for example sbyte It means signed One byte size ( 8 Bit binary bit ) The integer of , The value range is -128 to 127
The value range can be referred to
3. Determine the inheritance relationship of the type type 4. Types also affect program runtime , Is the variable stored in heap or stack ; What operators can variables use += -= Operators, etc.
Value type
Simple value types – Integer types 、 Character type 、 Real number type 、 Boolean type
Composite value type – Type of structure 、 Enumeration type
Value type And The difference between reference types
- Value type variables are stored on the stack , Directly store the data corresponding to the variable in the stack ; Reference type variables are stored on the stack , The data corresponding to the variable is represented as an address in the heap , This address represents the heap space where , Is the data of the reference object .
- Fast access to value types , Slow access of reference type .
- Value type variables represent actual data , Reference type variables represent pointers or references to data stored in the heap .
- Stack memory is automatically released , Heap memory consists of .NET GC Automatic release .
- Value types inherit from System.ValueType , Reference types inherit from System.Object.
Packing and unpacking
Boxing is to convert the value type to object Type or any interface type implemented by this value type
Packing : Convert value type variables into reference type variables
Unpacking : Convert reference type variables into value type variables
Type conversion
(int)1.2fint.Parse()var m = o as Mammal;Convert.ToString(value, baseValue)
Common container classes
ArrayList Variable length array
List<T> Generic linked list Fast access , Modification speed is slow
HashTable/Dictionary Hash table / Dictionary format High query efficiency It takes up a lot of space
Stack Stack Last in, first out
Queue queue fifo
ref and out The difference between
ref and out You can make the function have multiple returned values
Both keywords are parameters that decorate the function , It means that the function parameter is passed by reference instead of value copy , among out The passed reference only brings back the return value , There is no need to declare variables in advance
for forEach enumerator.MoveNext Memory consumption of the loop
for The loop can be traversed sequentially by index ,foreach and Enumerator.MoveNext Iterate through , Memory consumption doesn't make much difference in essence
Be careful : Use forEach The element being traversed cannot be deleted when looping , After traversal , Delete the corresponding index or key The elements of
边栏推荐
- Introduction to redis II: RedHat 6.5 installation and use
- Oracle库访问很慢,是什么原因?
- High beam software has obtained Alibaba cloud product ecological integration certification, and is working with Alibaba cloud to build new cooperation
- 云原生编程挑战赛火热开赛,51 万奖金等你来挑战!
- Oracle library access is slow. Why?
- “当你不再是程序员,很多事会脱离掌控”—— 对话全球最大独立开源公司SUSE CTO...
- 微信公众号授权登录后报redirect_uri参数错误的问题
- 到底为什么不建议使用SELECT * ?
- C reads the data in the CSV file and displays it after importing the DataTable
- Explain several mobile ways of unity in detail
猜你喜欢

Ask if you don't understand, and quickly become an advanced player of container service!

PL515 SOT23-5 单/双口 USB 充电协议端口控制器 百盛电子代理商

全链路灰度在数据库上我们是怎么做的?

Prometheus complete process of configuring alertmanager
![[C语言刷题篇]链表运用讲解](/img/44/1de4e3f0712780680fbdc904dfe39a.png)
[C语言刷题篇]链表运用讲解

Thinking and summary of R & D Efficiency

融合数据库生态:利用 EventBridge 构建 CDC 应用

Introduction to redis I: redis practical reading notes

System. ArgumentException: Object of type ‘System. Int64‘ cannot be converted to type ‘System.Int32‘

How bad can a programmer be? Nima, they are all talents
随机推荐
JS drag and drop alert pop-up plug-in
Two written interview questions about regular
Algorithm interview high frequency problem solving guide [1]
JS picture hanging style photo wall JS special effect
Redis的三种删除策略以及逐出算法
Introduction to redis II: RedHat 6.5 installation and use
Interpretation of ue4.25 slate source code
[complete collection of common ADB commands and their usage (from a comprehensive summary of [wake up on Sunday)]
Introduction to redis I: redis practical reading notes
JS fly into JS special effect pop-up login box
JS win7 transparent desktop switching background start menu JS special effect
C# 委托 delegate 的理解
动态规划:背包问题模板代码汇总
View the thread stack according to the lwtid of opengauss/mogdb.
不懂就问,快速成为容器服务进阶玩家!
Unity performance optimization
瀚高数据库最佳实践配置工具HG_BP日志采集内容
全链路灰度在数据库上我们是怎么做的?
平均海拔4000米!我们在世界屋脊建了一朵云
Learn about the native application management platform of rainbow cloud