Csharp notes
Csharp notes
Csharp notes
coding style easier to read and understand.provide meaning ful variable and
function names.
what is c#?
1)csharp is one of the microsoft programming language to work with .net framework
and .net core using this we can build different types of applications.
2)csharp is completely object-oriented programming language.it supports 4
principles Inheritance,Abstraction,polymorphism,and Encapsulation.
What is typecasting?
1)typecasting is the process of changing one datatype value in to another datatype
value.
Types of Casting :they are two types.1)implicit 2)Explicit both should be
compatiable to each other.
1)the implicit type casting is automatically done by the compiler from a smaller
datatype to larger datatype.There will be no data loss.
ReadOnly Struct:
1)When we declare a field using the readonly modifier.readonly modifier indicates
to the fields only part of the declaration or in a constructor of the same
class.readonly only fields can only be assigned or reassigned multiples times only
at the declaration or in a constructor.
What is concurrentBag<T> class in c#?
1)
Object-Oriented programming
class:
A class is user-defined data type that represent both state and behaviour. the
state represents the properties and behaviour is the action that object can
perform.
object:
Object is an instance of a class.All the memebers of a class can be accessed
through the object.to access the class members we need to use the (.) dot
operator.if we want to create an object of a class we need to use the new keyword.
**Types of Classes:
1)Abstract Class 2)sealed class 3)partial class 4)static class
Encapsulation:
1)Encapsulation hides the internal state and functionality of an object and only
allows access through a public set of functions.
2)The process of binding the data members and member function together into a sinle
unit. [Class , interface ,Enum ,Struct etc ]
3)Using Encapsulation we can achieve Data Hiding. is a process which we hide the
internal data from the outside world.
4)We declare variable as private to stop accessing them directly from the outside
world. the public getter and setter methods are used to access the private
variables from outside the class.
What is a constructor?
1)Constructor is a special method present inside a class that is responsible for
initializing the variables of that class.
2)the name of the constructor is exactly the same name as the class.
3)Every field or variable we declared inside a class has a default value.
4)we can also define a constructor under the class and if we define it .we can call
it an explicit constructor and an explicit constructor can be parameter less and
parameterized also.
Types of Constructors:
1)Default or parameter less Constructor 2)Parameterized constructor
3)private constructor 4)static constructor 5)copy constructor
using this access modifier we are able do who can access them and who cannot access
them.
OOPS
Inheritance:
1)A class is collection of members. the members defined in one class can be
consumed by another class by establishing relationship between two classes.
2)Using inhertiance we avoid rewriting the code.
3)Derived class can consume all the bass class members(public and protected) except
private(we can use protected method to access private member).
[Base Keyord is used to access the base class methods ,constructors ,properties
from the derived class.
Polymorphism:
1)The word polymorphism is derived from two greek words poly and morphs.the word
poly is many and morphs means forms.
using polymorphism we can perform a single task in different ways.behaving in
different ways depending on the input received.
we can perform various operations by using methods with the same name.
**[while working with polymorphism we need understand two things 1)what happens at
the time of compilation and Execution for a given method call.
method overloading:
------------------
method overloading is one of the common way to implement compile-time polymorphism.
1)When multiple methods have the same name but different parameters.it allows the
compiler to decide which method to call based on the arguments provided.
How we can re-implement the parent class method under child class?
in to two different approaches. 1)Method Overriding and 2)Method Hiding
Partial class:
-------------
1)To Make any class partial we need to use partial keyword. partial class allows us
to define a class on multiple files.we can physically spilt the content of the
class but logically it is one single unit only.
2)the class file names are different but the class name is going to be the same.
all parts of the partial class must have the same access modifier.
Sealed class:
-------------
1)to make any class sealed we need to use keyword sealed .Sealed class cannot be
inherited any other class.
*2)Sealed class cannot contain any abstract methods.
sealed method:
---------------
1)The method that is defined in a parnet class. If that method cannot overridden
under a child class. if the method is declared as sealed that cannot be inherited.
2)Evey method is a sealed method because overriding is not possible unless the
method is not declared as virtual in the parnet class.
3) If a method is declared as virtual in a class, any child class of it can have
the right to override that method.
Extension Method:
----------------
1)Extension method allows us to add new methods into a class without editing the
source of the class.if a class consists a set of members in it and in the future if
you want add new methods into the class .we can add those methods without making
any changes to the source code of the class.
2)Extension methods must be defined only under the static class.we can able to
create instance of extension an class .because another class is a non-static class.
the method changes into non-static.
3)the frst parameter is a binding parameter which should be the name of the class.
Static class:
------------
1)The Class Which is created by using the static Modifier is called static class. A
static class can contain only static members.It is not possible to create a
instance of a static class.using the static class name we can directly access
static members.
2)A static class cannot inheratie another class.