Introducing Radical.sh

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

Property - Example in C#

Example:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace ForgetCode
  7. {
  8. public class Employee
  9. {
  10. public static int numberOfEmployees;
  11. private static int counter;
  12. private string name;
  13.  
  14. // A read-write instance property:
  15. public string Name
  16. {
  17. get
  18. {
  19. return name;
  20. }
  21. set
  22. {
  23. name = value;
  24. }
  25. }
  26.  
  27. // A read-only static property:
  28. public static int Counter
  29. {
  30. get
  31. {
  32. return counter;
  33. }
  34. }
  35.  
  36. // Constructor:
  37. public Employee()
  38. {
  39. // Calculate the employee's number:
  40. counter = ++counter + numberOfEmployees;
  41. }
  42. }
  43.  
  44. public class MainClass
  45. {
  46. public static void Main()
  47. {
  48. Employee.numberOfEmployees = 100;
  49. Employee e1 = new Employee();
  50. e1.Name = "Claude Vige";
  51. Console.WriteLine("Employee number: {0}", Employee.Counter);
  52. Console.WriteLine("Employee name: {0}", e1.Name);
  53. }
  54. }
  55. }


Output:
  1. Employee number: 101
  2. Employee name: Mark