Professional Documents
Culture Documents
C# Method
C# Method
Net
Types of Methods in C#.Net:
Methods
• Abstract Method
• Virtual Method
• Override Method
• Static Method
• Main Method
Method:
In object-oriented programming, a method is a subroutine (a portion of code) that is
exclusively associated either with a class or with an object. A method usually consists of a
• and possibly an output value (called the return value) of some kind.
Methods provide a mechanism for accessing and manipulating the encapsulated data stored in an
object.
Abstract Method:
An Abstract Method is a method which is just declared but not implemented in the same class.
It is declared with keyword Abstract. This method is implemented with keyword “override” in the child
class. An abstract method can only exist in an abstract class. A class which implements the abstract
class must implement all its abstract methods.
Virtual Method:
A Virtual Method is a method which is just declared but not implemented in the same class. It
is declared with keyword Virtual. This method is implemented with keyword “override” in the child
class. A virtual method can exist in a non-abstract i.e. simple class. A class which implements the
virtual method needs not to implement all the virtual methods exist in that class.
Public Class C1
Override Method:
An override Method is a method which is written in child class to override or implement the
body (functionality) of the method of parent class. It is declared with key word override. In C#
Override method is normally used to override the parent public/protected methods in the child class or
is used to implement virtual or abstract method of parent class in the child class.
Main Method:
Main is very important keyword in any language like C#. A Method having a name “Main” is
the first method in the application which is executed by the compiler from the memory, once the
application is loaded in the memory. To the load the main method in the memory for the execution, it
must be declared static.
In C# programming the Main method is where program starts execution. It is the main entry point
of program that executes all the objects and invokes method to execute. There can be only one
Main method in C#. However, the C# Main method can be void or int return type. It must be
inside a class or struct and must be declared with static modifier. It is t he main place where a
program starts the execution and end. The Main method can have a parameter and these
parameters are kno wn as zero-indexed command line argument.