using System;public class Student { public int Id {get;set;} public string Name {get;set;}}public class Program { public static void Main() { var s1 = new Student(){Id = 1, Name = "Ram"}; var s2 = new Student(); s2 = s1; s2.Id = 2; s2.Name = "Shyam"; Console.WriteLine("Id:" + s1.Id + " , Name:" + s1.Name); }}
using System;
public class Student {
public int Id {get;set;}
public string Name {get;set;}
}
public class Program {
public static void Main() {
var s1 = new Student(){Id = 1, Name = "Ram"};
var s2 = new Student();
s2 = s1;
s2.Id = 2;
s2.Name = "Shyam";
Console.WriteLine("Id:" + s1.Id + " , Name:" + s1.Name);
The output is:- Id:2 , Name:Shyam
The aim of this question is to test the fundamental concept of reference type of object in C#. Here s1 and s2 are pointing the same location of a memory.
Id: 2 , Name: Shyam