Can you provide an example of a Reference Type in C#
class Program {// Example of a reference type: a simple classclass Person{public string Name { get; set; }public int Age { get; set; }public Person(string name, int age){Name = name;Age = age;}}static void Main(){// Creating an instance of the reference type (Person)Person person1 = new Person("John Doe", 25);// Creating another reference (person2) pointing to the same object as person1Person person2 = person1;// Modifying the object through one reference affects the other referenceperson1.Age = 30;// Both references point to the same object, so both will reflect the changeConsole.WriteLine($"person1: {person1.Name}, Age: {person1.Age}");Console.WriteLine($"person2: {person2.Name}, Age: {person2.Age}");} }
Examples of Reference Types are string, object, collections. int a=10; //it is store the there memory and it is store the stack memory object b=10; //it is store the reference memory and it is store the heap //memory.
Reference types store variable references. Examples of built in reference types include object, dynamic and string.Other examples of references types are MyClass obj = new MyClass();In this case obj is a reference to an instance of MyClass