Sobes.tech
Junior — Middle

Kas saaksite selgitada viidete andmetüüpide kontseptsiooni?

sobes.tech AI

Vastus AI-lt

Reference data types in C# are types that store not the data itself, but a reference to the memory area where this data is located.

Main features:

  • When assigning a variable of a reference type, the reference is copied, not the object.
  • Multiple variables can refer to the same object.
  • Changes made through one reference are reflected in all others.

Examples of reference types: classes (class), strings (string), arrays, delegates.

Example:

class Person { public string Name; }

Person p1 = new Person { Name = "Иван" };
Person p2 = p1; // p2 refers to the same object
p2.Name = "Пётр";
Console.WriteLine(p1.Name); // Will output "Пётр"

Here, changes through p2 affect p1, as both variables refer to the same object.