0% found this document useful (0 votes)
3 views

Oops concept

The document discusses key concepts in C# programming, including abstraction, encapsulation, access modifiers, abstract classes, interfaces, polymorphism, operator overloading, and delegates. It explains how these concepts help in simplifying code and managing complexity while providing definitions and examples for each. Additionally, it covers the use of generic delegates like Func, Action, and Predicate, as well as the concept of anonymous methods.

Uploaded by

Suraj Javarat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Oops concept

The document discusses key concepts in C# programming, including abstraction, encapsulation, access modifiers, abstract classes, interfaces, polymorphism, operator overloading, and delegates. It explains how these concepts help in simplifying code and managing complexity while providing definitions and examples for each. Additionally, it covers the use of generic delegates like Func, Action, and Predicate, as well as the concept of anonymous methods.

Uploaded by

Suraj Javarat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Abstraction:

we need to expose what is necessary and compulsory and we need to hide the unnecessary things from
the outside world. In C# we can hide the member of a class by using private access modifiers.

Encapsulation:
Hiding complexity

Encapsulation help us to make our class simpler to use or make our object to simpler to use.

Access modifier:

Private: Only member of class have access. Any external member can’t have access this faction.

Public: All the member have access in all class and projects.

Protected: All member have access in current class and derived class can access the variables.

Internal: Only member in current project have access to the element.

Protected internal: All member in the current project and all member in the derived class access in the
variable.

Abstract class:
1. Cannot create an instance of the abstract class or interface
2. Abstract class define the method but can’t define the body.

3. An abstract class can has constructors and destructor.


4. An abstract class cannot support multiple inheritance.
5. An abstract class can have access modifier.
6. We must be use the override keyword because we are define method in non-abstract class.
Interface:
1. Interface all methods are define public by default. & Interface can’t have access
modifier they are public by default

2. Interface can only contain declaration and no implementation (definition).


3. Interface cannot have contain fields (int Id).

4. A class can’t inherit from more than one class for the same time but class can inherit
from the more than one interface at the same time.
5. Can a class implementation interface with same method name?

Answer: Yes, to define two different implementations for same method name we need to use explicit
interface method implementation.

Polymorphism:
Definition: Polymorphism is basically allows you to invoked derived class methods through base class
reference variables at run time that’s polymorphism.

Definition: Polymorphism is sharing a common interface for multiple types but having different
implementation for different types.

Operator Overloading

Definition: Operator overloading gives the ability to use the same operator to do various operations.

Delegates

Definition: A delegate is a type-safe function pointer that can reference a method that has the same
signature as that of the delegate.

Advantage of delegates: in C# to implement events and call-back methods

Generic Delegates

1. Func - It takes one or more input parameters and returns one out parameter.

Func func1 = DelegateClass.Add;


int value = func1(10, 20);
2. Action - It takes one or more input parameters and returns nothing

Action action1=DelegateClass.ShowEmploye;
action1(30,"Rajesh");

3. Predicate - one input parameter and one Boolean return type either true or false.

Predicate predicate = (str) = & gt;


{
double retNum;
bool isNum = Double.TryParse(Convert.ToString(str), Sys
tem.Globalization.NumberStyles.Any, System.Globalization.Nu
mberFormatInfo.InvariantInfo, out retNum);
return isNum;
};
bool found = predicate("12232");

Anonymous Method

Is a method without having name. The anonymous methods in c# can be defined using keyword
delegates and can assign to variable of the delegates’ type.

You might also like