Introducing Radical.sh

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

GET and SET property in C#

This code is an example for the get and set property in C#.

  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. Example example = new Example();
  15. example.Number = 100; // set { }
  16. Console.WriteLine(example.Number); // get { }
  17. }
  18.  
  19.  
  20.  
  21. class Example
  22. {
  23. int _number;
  24. public int Number
  25. {
  26. get
  27. {
  28. return this._number;
  29. }
  30. set
  31. {
  32. this._number = value;
  33. }
  34. }
  35. }
  36. }
  37. }


  1. Output: 100


..