Advertisement
balrougelive

Untitled

Oct 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. /*
  2.  
  3. Create a class.
  4.  
  5. Define a single public integer field.
  6. Add a constructor that initializes the field to 0.
  7. In Main:
  8. Declare an object of your class.
  9. Set the integer of that object to a value.
  10. Print the value of that integer.
  11.  
  12. */
  13.  
  14.  
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20.  
  21. namespace Constructors
  22. {
  23. class Constructors // Class Named Constructors
  24. {
  25. static void Main(string[] args) // Main:
  26. {
  27. FreeConstructor free = new FreeConstructor(); //
  28. free.MyProperty = 0;
  29. free.Print();
  30.  
  31. }
  32. class FreeConstructor
  33. {
  34. public int MyProperty { get; set; }
  35. public void Print()
  36. {
  37. Console.WriteLine("MyProp: " + MyProperty);
  38. }
  39. }
  40. }
  41. }
  42.  
  43.  
  44. //using System.Collections.Generic;
  45. //using System.Linq;
  46. //using System.Text;
  47. //using System.Threading.Tasks;
  48.  
  49. //namespace Constructors
  50. //{
  51. // class ConstructorsExercise // Class Named Constructors
  52. // {
  53.  
  54. // static void Main(string[] args) // Main
  55. // {
  56. // freeConstructor vara = new freeConstructor(); // Declare an instance of an object of my defined class freeConstructor
  57. // Console.WriteLine(freeConstructor);
  58. // }
  59.  
  60.  
  61. // class freeConstructor // Class I made
  62. // {
  63. // public int myVariable { get; set; } // Define a public int field
  64. // public void Print()
  65. // {
  66. // Console.WriteLine("myVariable is:" + myVariable);
  67. // }
  68. // }
  69. // }
  70. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement