Calling a Method in C#

You can call a method in C# by specifying its name only. Here is an example:

Calling a Method in C# Example

In the following case,  a SomeMethod() will be called from the Main() method and after completing the SomeMethod() the control will return to the Main() method.

using System;

namespace CallingAMethod
    class CallingAMethod
        static void Main()
            Console.WriteLine("In Main! Calling SomeMethod( )...");
            Console.WriteLine("Back in Main( ).");
        static void SomeMethod()
            Console.WriteLine("Greetings from SomeMethod!");


In Main! Calling SomeMethod( )...
Greetings from SomeMethod!
Back in Main( ).

See also:

Leave a Comment