C#.NET Abstract method
Abstract method is a method which is created using "abstract"keyword.
It doesn't have any implementation or body.
It will have only signature.
Semicolon is required at the end of signature.
It is implemented in the class which inherits it.
Syntax for creating abstract method
abstract keyword access specifier return_type method_name(input parameters)
Example
abstract public long add(int a,int b);
It doesn't have any implementation or body.
It will have only signature.
Semicolon is required at the end of signature.
It is implemented in the class which inherits it.
Syntax for creating abstract method
abstract keyword access specifier return_type method_name(input parameters)
Example
abstract public long add(int a,int b);
C#.NET Method with arguments and return type
It is one of the method that contains both arguments and return type.
Example
public long add(int a,int b)
{
return a+b;
}
Example
public long add(int a,int b)
{
return a+b;
}
C#.NET Method with Return Type
It is one of the method that doesn't have any arguments/parameters. It contains only return type.
Example
public int add()
{
Console.WriteLine("addition");
return 1;
}
A method can return value to anything which is capable of holding that value.
Example
int i=add();
Console.WriteLine(i);//1
Explanation
In the above example the add method can return value'1' to i and it will be printed as output.
Example
public int add()
{
Console.WriteLine("addition");
return 1;
}
A method can return value to anything which is capable of holding that value.
Example
int i=add();
Console.WriteLine(i);//1
Explanation
In the above example the add method can return value'1' to i and it will be printed as output.
C#.NET Method with arguments
It is one type of method and consists of arguments/parameters.
Example
public long add(int a,int b)
{
Console.WriteLine(a+b);
}
Explanation
In the above example the add() can take two values of int type as inputs and doesn't return any type because long data type is a return type but in body section there is no return type.
Example
public long add(int a,int b)
{
Console.WriteLine(a+b);
}
Explanation
In the above example the add() can take two values of int type as inputs and doesn't return any type because long data type is a return type but in body section there is no return type.
C#.NET Simple Method
Simple method is a method that doesn't have any arguments and return type.
Syntax
Access specifier return type methodname( )
Example
public void add()
{
Console.WriteLine("addition");
}
Syntax
Access specifier return type methodname( )
Example
public void add()
{
Console.WriteLine("addition");
}
C#.NET Methods
- Method is a piece of code which is used to perform a particular task.
- A Method can be either no value returning or value returning.
- If it was a no value returning we will use void as return type for that method.
- If it was a value returning we use a specific type i.e., what type of value that a method returns.
Access specifier return type methodname( )
{
}
Access Specifier : It is used to define the accessibility level of a method.
Example for access specifiers are public, private, protected etc.
ReturnType: What type of value return by a method is given as return type.
Method name: The name of a method to call it.
Example
public void add()
{
//Code Logic
}
There are different types of methods
- C#.NET Simple Method
- C#.NET Method with arguments
- C#.NET Method with return type
- C#.NET Method with arguments and return type
- C#.NET Abstract Method
- C#.NET Static Method
C#.NET OOPS
OOPS stands for Object Oriented Programming Structure.
It was a new approach in programming introduced in 1970's when a suffered problems with procedural programming languages like lack of security and reusability.
Object Oriented approach provides us security and reusability of the code.
To call a language as Object Oriented it needs to satisfy a set of rules prescribed by an approach. Those are:
It was a new approach in programming introduced in 1970's when a suffered problems with procedural programming languages like lack of security and reusability.
Object Oriented approach provides us security and reusability of the code.
To call a language as Object Oriented it needs to satisfy a set of rules prescribed by an approach. Those are:
- Encapsulation
- Abstraction
- Inheritance
- Polymorphism