Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Create a class.
- Define a single public integer field.
- Add a constructor that initializes the field to 0.
- In Main:
- Declare an object of your class.
- Set the integer of that object to a value.
- Print the value of that integer.
- */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Constructors
- {
- class Constructors // Class Named Constructors
- {
- static void Main(string[] args) // Main:
- {
- FreeConstructor free = new FreeConstructor(); //
- free.MyProperty = 0;
- free.Print();
- }
- class FreeConstructor
- {
- public int MyProperty { get; set; }
- public void Print()
- {
- Console.WriteLine("MyProp: " + MyProperty);
- }
- }
- }
- }
- //using System.Collections.Generic;
- //using System.Linq;
- //using System.Text;
- //using System.Threading.Tasks;
- //namespace Constructors
- //{
- // class ConstructorsExercise // Class Named Constructors
- // {
- // static void Main(string[] args) // Main
- // {
- // freeConstructor vara = new freeConstructor(); // Declare an instance of an object of my defined class freeConstructor
- // Console.WriteLine(freeConstructor);
- // }
- // class freeConstructor // Class I made
- // {
- // public int myVariable { get; set; } // Define a public int field
- // public void Print()
- // {
- // Console.WriteLine("myVariable is:" + myVariable);
- // }
- // }
- // }
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement