Advertisement
Qrist

ValueAndRefTypes

Jun 29th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ValueRef
  4. {
  5.     public class Student
  6.     {
  7.         public string Name { get; set; }
  8.         public bool Enrolled { get; set; }
  9.  
  10.     }
  11.     public class AnotherClass
  12.     {
  13.         public static void Method(ref Student st)
  14.         {
  15.             st.Name = "Narine";
  16.             st.Enrolled = true;
  17.             st = new Student();
  18.             st.Enrolled = false;
  19.         }
  20.     }        
  21.     class Program
  22.     {
  23.         static void Main(string[] args)
  24.         {
  25.             Student an = new Student()
  26.             {
  27.                 Name = "Karine",
  28.                 Enrolled = false
  29.             };
  30.             AnotherClass.Method(ref an);
  31.             Console.WriteLine(an.Enrolled);
  32.         }
  33.  
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement