Home > Backend Development > C#.Net Tutorial > Value types and reference types in C#

Value types and reference types in C#

王林
Release: 2023-09-03 16:45:32
forward
1072 people have browsed it

C# 中的值类型与引用类型

Value types and references are both types in C# -

Value type

Value type variables can be assigned directly. They are derived from the System.ValueType class. Value types contain data directly. When the int type is declared, the system allocates memory to store the value.

Value type variables are stored on the stack.

For example, int, char and float, which store numbers, letters and floating point numbers respectively.

Reference type

It refers to a memory location. Using multiple variables, reference types can refer to memory locations. If data in a memory location is changed by one of the variables, the other variable automatically reflects this change in value.

Reference type variables are stored in the heap.

The example built-in reference type is -

  • object
  • dynamic
  • string

The above is the detailed content of Value types and reference types in C#. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template