How to call a method of a class in C#

To call a method, use the name of the method after the object name, for example, −

obj1. Display();

Let’s say the class name is ApplicationOne, so to call the method −

ApplicationOne one = new ApplicationOne();

//calling the displayMax method
ret = one.displayMax(a, b);

The following is the example showing how to call a method in C# −


 Live Demo

using System;

namespace Demp {
   class ApplicationOne {
      public int displayMax(int num1, int num2) {
         /* local variable declaration */
         int result;

         if (num1 > num2)
         result = num1;
         result = num2;
         return result;

      static void Main(string[] args) {
         /* local variable definition */
         int a = 700;
         int b = 400;
         int ret;
         ApplicationOne one = new ApplicationOne();

         ret = one.displayMax(a, b);
         Console.WriteLine("Max value is : {0}", ret );


Max value is : 700
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know