SEARCH C# PROGRAMMING CODES HERE

Methods

Methods in C#
The Method is a different code block that contains a series of explanations to play out specific activities and strategies must be declared either in class or struct by indicating the required parameters. When you characterize a method, you fundamentally declare the components of its structure. The Syntax structure for characterizing a method as follows

class Class_Name

    {
        <Access_Specifier> <Return_Type> Method_Name(<Parameters>)

        {

            /* Statements to Implement........*/

        }
    }

To utilize a method, you have to Characterize the method and then you can call the method. Following are the different elements to Characterizing a method.

1-Access_Specifier - It is utilized to characterize an entrance level either public or private.
To enable different classes to get to the method. In the event that we didn't specify any access modifier, at that point it is private.

2-Return_Type - It is utilized to determine the sort of significant worth the method can return. if the method is not returning any value, at that point we have to specify void as return type.

3-Method_Name - It must be a unique name to recognize the method in a class.

4-Parameters - The strategy parameters are utilized to send or get information from the method and these technique parameters are encased inside enclosures and are separated by commas. if no parameters are required for a technique, at that point, we have to characterize a method with void brackets.

Characterizing Parameter and return type and calling method program as follows.

Program
using System;

namespace Methods
{
    class Program /*Class_Name*/
    {

       /*Creating Main Method */ 
        static void Main(string[] args)
        {
            Program p = new Program();
            string Show = p.Display(" to the world ");
            Console.WriteLine( "Wellcome"+Show+"of Rohit Programming Zone" );
            Console.ReadKey();
        }
        public string Display(string Message) /*Parameter*/
        {
            return Message;   /*Calling Method*/
        }
      }
 }
       Output

No comments:

Post a Comment