Articles → CSHARP → Is Struct A Value Type Or Reference Type

Is Struct A Value Type Or Reference Type








How Does Value Type Work?





Example




public struct Book {

}




Book a = new Book();
Book b = a;
if (Object.ReferenceEquals(a, b)) {
	Console.WriteLine("Both objects are pointing to same location");
}
else {
	Console.WriteLine("Both objects are pointing to different location");
}






Picture showing the output of whether the struct is a value type or reference type
Click to Enlarge




Posted By  -  Karan Gupta
 
Posted On  -  Friday, April 24, 2015

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250