当前位置:网站首页>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
边栏推荐
- The average altitude is 4000 meters! We built a cloud on the roof of the world
- 有奖征文 | 2022 云原生编程挑战赛征稿活动开启
- 动态规划:背包问题模板代码汇总
- Interpretation of ue4.25 slate source code
- 微信公众号授权登录后报redirect_uri参数错误的问题
- Beautiful blue background form input box style
- Fragment中使用ViewPager滑动浏览页面
- Seventeen year operation and maintenance veterans, ten thousand words long, speak through the code of excellent maintenance and low cost~
- 既要便捷、安全+智能,也要颜值,萤石发布北斗星人脸锁DL30F和极光人脸视频锁Y3000FV
- Integrating database Ecology: using eventbridge to build CDC applications
猜你喜欢

一个程序员的水平能差到什么程度?尼玛,都是人才呀...

Redis 3.0源码分析-数据结构与对象 SDS LIST DICT

Unity uses shader to quickly make a circular mask

不懂就问,快速成为容器服务进阶玩家!

什么是数据中台?数据中台带来了哪些价值?_光点科技

How to use redis to realize things and locks?

什么是“安全感”?沃尔沃用它自己独特的理解以及行动来告诉你

Integrating database Ecology: using eventbridge to build CDC applications

js图片悬挂样式照片墙js特效

LVS+KeepAlived高可用部署实战应用
随机推荐
UE4 3dui widget translucent rendering blur and ghosting problems
Unity performance optimization
Redis入门二:redhat 6.5安装使用
作业 ce
Yum package management
Unity object path query tool
“当你不再是程序员,很多事会脱离掌控”—— 对话全球最大独立开源公司SUSE CTO...
JS fly into JS special effect pop-up login box
Prize essay solicitation | 2022 cloud native programming challenge draft activity opens
全链路灰度在数据库上我们是怎么做的?
【服务器数据恢复】HP StorageWorks系列存储RAID5两块盘故障离线的数据恢复案例
UE4.25 Slate源码解读
Oracle库访问很慢,是什么原因?
SQL审核工具自荐Owls
Space shooting Lesson 13: explosion effect
Fragment中使用ViewPager滑动浏览页面
h5微信射击小游戏源码
融合数据库生态:利用 EventBridge 构建 CDC 应用
漂亮的蓝色背景表单输入框样式
js图表散点图例子