Net Oops
Net Oops
NET OOPS
Agenda
Exception Handling
A problem that occurs during the execution of a programme is referred to as an exception.
Example: Attempting to divide by zero.
Syntax: try
{
// Code causing exception case
} catch( ExceptionName e1 )
{
// Code to handle exception
} catch( ExceptionName e2 )
{
} catch( ExceptionName eN )
{
// Code to handle exception
} DO NOT WRITE ANYTHING
finally HERE. LEAVE THIS SPACE FOR
{ WEBCAM
// statements to be executed
}
Exception Handling and Exploring Structs
Exception Classes in C#
● System.IO.IOException
● System.IndexOutOfRangeException
● System.ArrayTypeMismatchException
● System.NullReferenceException
● System.DivideByZeroException
● System.InvalidCastException
● System.OutOfMemoryException
● System.StackOverflowException
Exploring Structs
● Structure is a value type data type in C#.
● It allows you to combine relevant data from several data kinds into a single variable.
● A structure is created with the struct keyword.
Example:
struct novels
{
public string title;
public string author;
public int book_id;
};
Encapsulation
● The process of encapsulating one or more elements within a physical or logical container is
characterised as encapsulation.
● Encapsulation prohibits access to implementation details in object-oriented programming.
● An access specifier determines the scope and visibility of a class member. The following access
specifiers are supported by C#:
● Public
● Private
● Protected
● Internal
● Protected internal
Polymorphism
● Polymorphism refers to the fact that something exists in multiple forms.
● Polymorphism is commonly described in the object-oriented programming
paradigm as "one interface, numerous functions."
Abstraction
Abstraction in C# refers to the technique of hiding internal details and simply displaying functionality.
Abstract Method
An abstract method is one that is declared abstract and has no body.
Example: public abstract void write ( );
Abstract Class
An abstract class is one that has been declared abstract. There are both abstract and non-abstract methods
that can be used.
It's a class that can't create new objects (to access it, it must be inherited from another class).
Interface
An interface is an entirely "abstract class," having only abstract methods and properties (and no bodies)
Example:
// interface
interface living beings
{
void sleep(); // interface method (does not include a body)
void eat(); // interface method (does not include a body)
}
DO NOT WRITE ANYTHING
HERE. LEAVE THIS SPACE FOR
WEBCAM
Abstraction, Interface and Inheritance
Inheritance
● In C#, inheritance refers to the ability to build a class that inherits the attributes and actions of another
class.
● Derived Class (Child) - a class that is descended from another.
● The class being inherited from is called the base class (parent).
● Use the : sign to inherit from a class.
Syntax:
Delegates
● Delegate is a reference to a method in C#. In C and C++, it works similarly to a function pointer.
● Internally, a delegate declaration specifies a class that is inherited from another class of
system.delegate
● Syntax:
delegate <return type> <delegate-name> <parameter list>
Event Handlers
● The event is a delegate that has been encapsulated.
● Many people can subscribe to an event.
● In general, we utilised the Event to represent a single user activity, such as clicking a button.
● If the event has many subscribers, the event handler is called synchronously.
● Syntax:
public event EventHandler Event_Name;
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited