MyClass class that contains a private courseName instance variable, and a property to get and set its value. : private « Class Interface « C# / C Sharp






MyClass class that contains a private courseName instance variable, and a property to get and set its value.


using System;

public class MyClass
{
   private string courseName;

   public string CourseName
   {
      get
      {
         return courseName;
      } 
      set
      {
         courseName = value;
      } 
   }
   public void DisplayMessage()
   {
      Console.WriteLine( CourseName ); 
   } 
}
public class MyClassTest
{
   public static void Main( string[] args )
   {
      MyClass myMyClass = new MyClass();
      Console.WriteLine( "Initial course name is: '{0}'\n",myMyClass.CourseName );
      Console.WriteLine( "Please enter the course name:" );
      string theName = Console.ReadLine();
      myMyClass.CourseName = theName;
      Console.WriteLine();
      myMyClass.DisplayMessage();
   }
}
           
       








Related examples in the same category