In C#, data types are divided into two categories: Value Types and Reference Types. Reference types store references (or addresses) to the actual data, rather than the data itself.
When you create a reference type variable, it holds the address of the data in memory, not the actual value. Multiple variables can reference the same object in memory.
class Person { })int[] numbers;)When you assign one reference type variable to another, both variables point to the same object. Changes made via one variable affect the other.
class Person
{
public string Name;
}
Person person1 = new Person();
person1.Name = "Alice";
Person person2 = person1; // Both refer to the same object
person2.Name = "Bob";
Console.WriteLine(person1.Name); // Outputs: Bob
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!