C# Program to Implement Static Method

«
»

This is a C# Program to implement static method.

Problem Description

This C# Program Implements Static Method.

Problem Solution

Here Static methods have no instances. They are called with the type name, not an instance identifier.

advertisement
Program/Source Code

Here is source code of the C# Program to Implement Static Method. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Implement Static Method
 */
using System;
class Program
{
    static void stamethod()
    {
        Console.WriteLine("Static Method");
    }
    void MethodB()
    {
        Console.WriteLine("Instance Method");
    }
    static char stamethod2()
    {
        Console.WriteLine("Static Method");
        return 'C';
    }
    static void Main()
    {
        Program.stamethod();
        Console.WriteLine(Program.stamethod2());
        Program programInstance = new Program();
        programInstance.MethodB();
        Console.Read();
    }
}
Program Explanation

This C# program is used to implement static method. Here we have created two static methods; Hence Static methods have no instances. They are called with the type name, not an instance identifier.

advertisement
Runtime Test Cases
 
Static Method
Static Method
C
Instance Method

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn