Types of method in csharp with oops - codebugfree

If you are the beginner programmer than you are always confuse in c sharp method. It is very difficult to know the method in csharp. Also advance programmer is also doing the mistake in method. There are diferent types of method we see one by one. In this method we will use inside the oops concept. Outside of oops it is very easy to use but inside oops method is very difficult. The types of method are listed below


Categories of method in csharp

1)  Method with no argument and no return value

Example of code

void Message()

{

Console.WriteLine("Thanks for visit our website");

Console.ReadLine();

}

2) Method with no argument but their is return value

Example of code

int sum()

{

int num1 = 10;

int num2 = 20;

int result;

result = num1+num2;

return result;

}

3) Method  with argument but their is no return value

Example of code

void sum(int num1 , int num2)

{

int result;

result = num1+num2;

Console.WriteLine("result");

Console.ReadLine();

}

4) Method with argument and return value.

This example is we will see in the main code in below.

Now we will make the some practice problem of code that code has capable to find the greater number of two integers digit. We input the two different number and program is find the automatic the greatest number.


 class Program
    {
        public int Find_greater(int num1,int num2)
        {
            int result;
            if (num1 > num2)
            {
                result = num1;
            }
            else
            {
                result = num2;
            }
            return result;
        }
        static void Main(string[] args)
        {
            Program greater_find = new Program();
            int ok_get = greater_find.Find_greater(111,9000);
            Console.WriteLine(ok_get);
            Console.ReadLine();
            greater_find.mesage();
            Console.ReadLine();
            
        }
        //method with no argument and return value
        void mesage()
        {
            Console.WriteLine("THanks for viditing our website");
            Console.ReadLine();
            
            
        
        }
    }

It is the program in line number three their is use the method that method is use argument and return the value. Two arguments is return and compire with if else and that value is return in result. we input the number from creating the object with class and call that method and input value. 

And last that is the example of the method with no argument and no return value. Practice all the types of method to master in the c sharp programming language.

Post a Comment

0 Comments