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#?

下次还敢
Release: 2024-04-04 16:21:16
Original
479 people have browsed it

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>
Copy after login

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>
Copy after login

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!

Related labels:
c#
source:php.cn
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template