Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

BOXING and UNBOXING example in C#

This is the example for Boxing and unboxing.
Note that both value type and reference type yield the same result.
This is illustrated below.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace forgetCode
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14. string mine = "Forget code";
  15. String referenceType1 = mine; //Boxing
  16. string valueType1 = referenceType1; //Unboxing
  17.  
  18. bool b = true;
  19. Boolean referenceType2 = b; //Boxing
  20. bool valueType2 = referenceType2; //Unboxing
  21.  
  22.  
  23. Console.WriteLine(mine);
  24. Console.WriteLine(referenceType1);
  25. Console.WriteLine(valueType1);
  26.  
  27. Console.WriteLine(b);
  28. Console.WriteLine(referenceType2);
  29. Console.WriteLine(valueType2);
  30. }
  31.  
  32. }
  33. }
  34.  


  1. Output:
  2. Forget code
  3. Forget code
  4. Forget code
  5. True
  6. True
  7. True