Value types and reference types in layman's terms: there's a different place to store,
Value type int double bool char struct (struct) enum (enum) is stored on top of the managed heap,
Reference type: The String object class is stored on the stack.
In simple terms, such as int a=1; int b=a; When you assign a value to B, you copy the value of a, and you create an area in the center of the memory to save the value of B. The storage of A and B is independent
Class A=new class (); class B=a; When assigning a value to B, simply copy the reference address of A to B. So that A and B point to the same address in memory. A and B are associated.
A value type is a reciprocal assignment between an object and an object
A reference type assigns a pass that has no value for the reference address
Class Program
{
public class staff
{
//reference type
public string FirstName {get; set;}
public string LastName {get; set;}
public int Salary {get; set;}
}
public struct Employee
{
public string FirstName {get; set;}
public string LastName {get; set;}
public int Salary {get; set;}
}
}
static void Main (string[] args)
{
Staff S1 = new Staff {FirstName = "123"};
Staff s2 = S1; Assignment-only addresses are not assigned a value
S2. FirstName = "ABC";
Employee E1 = New Employee {FirstName = "123"};//e1= "123"
Employee e2 = E1;
E2. FirstName = "ABC";
Console.WriteLine ("s1=" + S1. FirstName + ", e1=" + E1. FirstName);
}
Final output S1=ABC e1=123
C # Value types and reference types