Class declaration with a public method that has a parameter. : public « Class Interface « C# / C Sharp






Class declaration with a public method that has a parameter.


       

using System;

public class MyClass
{
   public void DisplayMessage( string courseName )
   {
      Console.WriteLine( "Welcome to the grade book for\n{0}!",courseName );
   }
}
public class MyClassTest
{
   public static void Main( string[] args )
   {
      MyClass myMyClass = new MyClass();
      Console.WriteLine( "Please enter the course name:" );
      string nameOfCourse = Console.ReadLine(); 
      Console.WriteLine(); 
      myMyClass.DisplayMessage( nameOfCourse );
   } 
}
    
       








Related examples in the same category

1.Class declaration with one public method.
2.MyClass class with a public constructor to initialize the course name.
3.A public constructor initializes private instance variable balance through public property.
4.User-defined public method