In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you the example analysis of C# median type and reference type, I believe that most people do not know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it!
Concept:
1. Value type: the data is stored in the stack of memory, and the data can be quickly accessed from the stack, so the value type represents the actual data.
two。 Reference type: represents a pointer or reference to data stored in the memory heap (including classes, interfaces, arrays, and strings).
The value types defined in C # include original types (Sbyte, Byte, Short, Ushort, Int, Uint, Long, Ulong, Char, Float, Double, Bool, Decimal), enum, struct
Reference types include: classes, arrays, interfaces, delegates, strings, and so on.
Difference:
The basic difference lies in the way they are stored in memory. Value types store values only in memory, and these value types are stored in the stack. Raw data types, such as bool and int, belong to this type. The memory unit of the reference type stores only the address of the object in the memory heap, and the object itself is placed in the memory heap. If the value of the referenced value type is null, no object is referenced.
The difference between heap and stack:
Heap and stack are two different concepts, and their storage locations in memory are also different.
Heaps are typically used to store variable-length data, such as string types
The stack is used to store fixed-length data, such as integer data int (four bytes per int variable). You can know from the location of the data store that when one value variable is assigned to another value variable, two identical values are saved in the stack, while a reference variable is assigned to another reference variable. two references to the same heap location are saved in the stack, that is, the address of the same heap is saved in the stack. When performing data operations, for value types, because each variable has its own value, the operation on one variable does not affect other variables. For variables of reference type, to operate on the data of one variable is to manipulate the data of that variable in the heap. If two variables of reference type refer to the same object, the actual meaning is that the address of the heap they hold in the stack is the same, so the operation on one variable will affect another variable that references the same object.
Concept:
1. Value type: the data is stored in the stack of memory, and the data can be quickly accessed from the stack, so the value type represents the actual data.
two。 Reference type: represents a pointer or reference to data stored in the memory heap (including classes, interfaces, arrays, and strings).
The value types defined in C # include original types (Sbyte, Byte, Short, Ushort, Int, Uint, Long, Ulong, Char, Float, Double, Bool, Decimal), enum, struct
Reference types include: classes, arrays, interfaces, delegates, strings, and so on.
Difference:
The basic difference lies in the way they are stored in memory. Value types store values only in memory, and these value types are stored in the stack. Raw data types, such as bool and int, belong to this type. The memory unit of the reference type stores only the address of the object in the memory heap, and the object itself is placed in the memory heap. If the value of the referenced value type is null, no object is referenced.
The difference between heap and stack:
Heap and stack are two different concepts, and their storage locations in memory are also different.
Heaps are typically used to store variable-length data, such as string types
The stack is used to store fixed-length data, such as integer data int (four bytes per int variable). You can know from the location of the data store that when one value variable is assigned to another value variable, two identical values are saved in the stack, while a reference variable is assigned to another reference variable. two references to the same heap location are saved in the stack, that is, the address of the same heap is saved in the stack. When performing data operations, for value types, because each variable has its own value, the operation on one variable does not affect other variables. For variables of reference type, to operate on the data of one variable is to manipulate the data of that variable in the heap. If two variables of reference type refer to the same object, the actual meaning is that the address of the heap they hold in the stack is the same, so the operation on one variable will affect another variable that references the same object.
The above is all the content of the article "sample Analysis of value types and reference types in C#". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.