Home >Backend Development >C#.Net Tutorial >What are the two major types of data types in c#?

What are the two major types of data types in c#?

下次还敢
下次还敢Original
2024-04-04 16:21:16535browse

The two major data types in C

#The data types in C# are divided into two major categories: Value type and Reference type .

Value type

  • Store in the stack
  • Copy data directly
  • Modifying the value type will not affect other variables
  • Includes: integers, floating point numbers, Boolean values, structures, enumerations
  • Example:
<code class="c#">int i = 10;
int j = i;
i = 20;
Console.WriteLine(j); // 输出 10</code>

Reference type

  • Stored in the heap
  • Storing references to objects
  • Modifying the reference type will affect other variables
  • Including: classes, interfaces, arrays, strings
  • Example:
<code class="c#">string s1 = "Hello";
string s2 = s1;
s1 += " World";
Console.WriteLine(s2); // 输出 Hello</code>

The above is the detailed content of What are the two major types of data types in c#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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