C# class and object
C# is an object-oriented programming language. The foundation of an object-oriented programming is a type system universe. In the type system universe, everything revolves around classes and objects.
In C#, a class is a representation of a type of object. It is a blueprint / plan / template that describes the details of an object. In simple terms, a class is a concept and an object is real entity with value.
For example, a Person is a class. A person has some attributes such as a person has a name, a date of birth, and sex. All real people are objects that are of a Person type. Each person object has a name, a date of birth, and sex but the values of these attributes may be different. The attributes of a class are called properties.
Not only a person has attributes, a person can also do something. For example, a person can eat, sleep, talk, or walk. The activities of classes are represented in form of events and methods.
Declaring a class
The following code example shows how to create a class and objects.
A class always starts with the keyword class followed by a class accessibility level, public or private. The following code snippet declares a public class named Person. That means, the class is public and accessible anywhere in the code.
For Ex:
public class person
{
}
A class has an access modifier. The access modifiers sets the boundaries and access levels of classes. C# supports public, private, protected, internal, and protected internal access modifiers.
Public- Public class is visible in the current and referencing assembly.
Private- Visible inside current class.
Protected- Visible inside current and derived class.
Internal- Visible inside containing assembly.
Internal protected- Visible inside containing assembly and descendant of the current class
Modifiers refine the declaration of a class. The list of all modifiers defined in the table are as follows;
Sealed- Class can't be inherited by a derived class.
Static- Class contains only static members.
unsafe- The class that has some unsafe construct likes pointers
Abstract -The instance of the class is not created if the Class is abstract
Types of classes:
C# language has different types of classes, such as static classes, abstract classes, partial classes, and sealed classes. you can find more details about class on below link.
What is Polymorphism?
Polymorphism is one of the core properties of an object-oriented programming. It allows a language method to do various things using the same name. Method overloading, operator overloading, and method overriding are the examples of polymorphism. C# language supports both method overloading and method overriding.
Please visit given link for more details.
Method Overloading
Method overloading allows class creators to use same method name with different signatures. This is useful to write clean code. For example, if you have a Calculator class that has a method, Add. The Add method can add integers, floats, doubles, and longs. We can use the same Add method name with different argument types in method signatures.Please visit given link for more details.
https://c-sharpprograms.blogspot.com/p/method-overloading-in-c.html
Sometimes there is a class which does not create objects; this class provides a definition to other derived classes. This class is known as an abstract class and the method is known as an abstraction.
Method Overriding
Method overriding is a language feature that allows a class to override a specific implementation of a a base class. The derived class can give its own definition and functionality to the method. However, the method signature must be the same as of the base class.
Inheritance allows a class to be reused by other classes that may need the same functionality. Inheritance works as a parent and child, where the parent is called a base class and the child is called a derived class. A derived class inherits almost all of the functionality of a base class unless it is restricted by private access modifier.
Please visit given link for more details.
Inheritance
C# is an object-oriented programming language. Inheritance is one of the key features of an object-oriented programming language.Inheritance allows a class to be reused by other classes that may need the same functionality. Inheritance works as a parent and child, where the parent is called a base class and the child is called a derived class. A derived class inherits almost all of the functionality of a base class unless it is restricted by private access modifier.
Please visit given link for more details
What is Abstraction?
Sometimes there is a class which does not create objects; this class provides a definition to other derived classes. This class is known as an abstract class and the method is known as an abstraction.Please visit given link for more details.
https://c-sharpprograms.blogspot.com/p/abstraction-and-abstract-class-in-c.html
Interfaces
Interfaces are not often use types in C#. C# language support single interface.An interface provides a skeleton of a class that must be implemented by the inherited class. It enforces derived classes to implement certain functionality.In C#, a class is a reference type and an interface is a value typePlease visit given link for more details.
No comments:
Post a Comment
Please let me know if you have any feedback or doubts.