You are on page 1of 32

Console Apps: The application where we don't have a GUI, and which can be

directly interacted with h/w components.


- Windows Apps
- Mobile Apps
- Web Apps
- Service Based Apps

Stand alone:
- It is also known as single user apps
- Single user at a time will communicate with that application.
- For every user it is must to have a seperate installation.
- Console, Windows, Mobile etc.
Distributed:
- It is also known as Multi user apps
- Multiple users will communicate with the application at a single time.
- The application need to be installed in "Server" and can be accessed with the
help of "client".
- Web Application

What is .Net?
- .Net is a framework and also a runtime/execution time environment for all
the .Net applications.

Why .Net is used?


- It can be used to build any type of application that is existed in IT Industry.
- Console, Windows, Mobile, Web, Service Based apps etc.
-----------------------------------------------------------------------------------
---------------------------
Programming Language: It is a set of instructions, which are used to communicate
with the OS.
- These components will communciate by using "Binary/Native" code (0 and 1).
- Writing the binary code is not possible by the developer becasue it is the
combination of 1 and 0, so that we will programming languages like C,C+
+,Java,VB.Net, C#.Net etc.
- The convertion of PL code into Binary code will be taken care by "compiler".

Is .Net is a Programming Langauge?


- It is not a PL, rather it contains collection of PLs
- It supports aroung 60+ PL, in that Microsoft have invented 11PL remaing all are
third party companies.
- VB.Net, C#.Net, J#.Net, F#.Net, C Omega, VC++, Windows Power Shell, Iron Python,
Iron Ruby, Typescript etc.

Technology:
- It is limited to build a kind of application or used to do a perticular task.

Is .Net is a Technology?
It is not a technology, rather it is a collection of technologies
- ASP.Net, ASP.Net Core,ADO.Net, WPF,XAMARIN etc.

Tool:
- Which is used to speed up the development time, by provinding auto generation.

Is .Net is a Tool?
- No, it support different tools like IDE tool(Visual Studio and SSMS) and ORM
Tools(LINQ and EF).
Framework:
- It is a collection of things together to build the application.
- .Net is a framework, beacuse it is having collection of things like
- Programming languages
- Technologies
- Tools
- Applications
- Class Libraries (Asembly).
-----------------------------------------------------------------------------------
---------------------------
Compiler:
- Compiler is used to check the syntactical error.If there is no error it will
perform convertion.
- Compiler is used convert the program into machine understandable format.

- Platform: It is the combination of Operating System and Processor acrchitecture.


- Platfrom Indepedendent: The application that we have developed by using one
platform, if it get executed by using another platform as well.
- Platform Dependent: The application that we have developed by using one platform
and if it get executed by only in that platform.

Is .Net is a platform Indepedent or not?


- No, It is depedent on Windows OS, beacuse CLR is sepcially designed only for
Windows OS.
- But if we want to build platform indepednt applications, will
integarte MONO framework to the CLR.
- Then we are able to build Platform Independent applications.
- Now both are integrate together we use ".Net Core".

Language Interoperability:
- The code that was developed in one PL can be consumed in another PL.
-----------------------------------------------------------------------------------
-----------
----------------
Components of .Net/ .Net Framework:
.Net => Framework + Runtime/Execution Environment
.Net => Class Librabries + CLR(Common Language Runtime)

Common Language Runtime:It is runtime environment which can be used to execute


all .Net supported language in an unique way.
- CLR is used to convert MSIL code into the native/binary code by ading some
features
- It contain majorly 4 components
n n n n n n n n
- Common Language Specification(CLS)
- Common Type System(CTS)
- Garbage Collector(GC)
- Just In Time Compiler(JIT)

Common Lanuguage Specification(CLS):


- Language specification means syntactical rules to write the code.
- Every PL has it's own syntax to write the code, but CLR is able to execute all
the PL, beacuse CLR is having it's own language specification for it's MSIL.
- CLR is not having any language specification of C#.Net/VB.Net/J#.Net etc. rather
it contains it's own langauge specification for it's MSIL.
- This language specification is avaible in a component of CLR i.e. CLS.
- Beacuse of this we can achive "Language Interoprability".

Common Type System(CTS):


- In CTS, type is nothing but datatype.
nnnnnnn nnnm mnmnmnm
- Every PL has it's own datatypes to define a variables, but CLR
is execute all the PL, beacuse CLR is having it's own datatype in a component i.e.
CTS.
- These datatypes are common to all the PL's supported by .Net, because all
the .Net supported programming langauges after language compilation it generates a
common code i.e. "MSIL".

* What are the datatypes supported in .Net/CTS?


- .Net supports two types of datatypes
- Value Types
- Reference Types

Value Types:
- It will store value directly into the memory location.
- These are stored in Stack memory.
- Examples: int, double, float, char,structure,enum etc.
- Every value type is a structure.
- The process of converting value type to reference type is known as "boxing".
- CLR is not providing automatic memory management for value types(Stack memory)

Reference Type:
- It will store the address of the value.
- These variables are stored in stack memory and values in Heap memory.
- Examples: Array,String, Class, interface, delegates etc.
- Every reference type is a "Class".
- The process of converting reference type to value type is known as "unboxing".
- CLR is providing automatic memory management for the heap memory/Reference type
members.
-----------------------------------------------------------------------------------
--------------------------------------
Garbage Collector:
- It is component of CLR, which can be used to perform automatic memory management.
- Whenever we run the applications, internally it create the objects and all these
objects are store in the Heap memory.
- If the objects are completely filled we can't able to open/create a new
application.
- To overcome above situation GC will look into memory and identify two kinds of
objects like
- Objects that are in use
- Objects that are idealed
- Whenever it find idealed objects then immediatly it will kill those objects.

Why CLR's GC is more efficient the JVM's GC?


- In CLR's GC it is divided the completely heap memory into 3 portions.
Genaration: It is portion of heap memory.
- Each portion heap memory is called Gen-0,Gen-1,Gen-2.
- Newly created object will always placed into Gen-0, when Gen-0 is filled it will
kill idelaed objects and objects that are currently in use those are moved into
higher generations automatically.

Note: We can explicitly call the Garbage collector by using "GC.Collect();"

JIT(Just In Time) Compiler:


- It is used to convert MSIL code into Native/Binary code.
- .Net code will gets executed two times
- Language Compiler - Errors and Convert to MSIL
- JIT Compiler - MSIL to Native/Binary
Note: JIT Compiler compilation is very fast compared with Language Compiler.

Class Librabries :
- It is a collection of classes.
- These class librabry is of two types
- User Defined
- User/Developer for projects.
- If it is user defined class library it should be under project
folder
- It is having file extensions of eigther *.dll or *.exe
- System Defined
- Microsoft for all the .Net applications.
- It is under GAC(Global Assembly Cache), the physical
location of GAC is "C:\Windows\assembly".
- These comes with a file extention "*.dll"(Dynemic Link
Librabry)

What is the difference between *.dll (vs) *.exe?


*.dll:
- It stands for Dynemic Link Library.
- A class without Main() after build will create the DLL
- These files are more reusable.
- It contain code in the form of MSIL.
- These files can't run independently, rather we need to add the reference of any
of project types like Console, Windows or Web.

*.exe:
- It stands for Executable file.
- A class with Main() after build will create the EXE.
- These files are not reusable.
- It contains the code in the form of Binary/Native.
- These file will run/execute independently.
-----------------------------------------------------------------------------------
-----
S/W requirements for .Net:
- Visual Studio Community 2022
- Sql Server Management Studio(SSMS) - 2018 - IDE Tool
- Sql Server - DB Server
- Windows OS/Mac OS

What is the Difference between IDE and Code Editor?


- IDE stands for Integrated Dev Environment, where we can write the code and
compile it and also execute it. Example: Visual Studio,SSMS, Eclipse etc.
- But if it is a Code Editor we can just write code and to compile and run will
depend on another enviroments.Examples: Notepad, Notepad++,Sublime, Brackets etc.

Note: To build .Net application it's not mandatory to use Visual Studio, we can
build by using simple Notepad also.

Console App Development:


- These applications are not having User Interface, Everything will be display in a
plain text and in the command prompt.
- To work with console app, we have a class i.e. "Console", which is presented
under "System" namespace.

Structure of Console App:


using System;
namespace CAFirst
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to C#.Net");
}
}
}

Namespace:
- A Namespace is a collection of classes.
- It is a logical container of classes.
- A namespace which is used to avoid the naming collission between the classes.
- If we want to use Microsoft classes then that relevent namespace should be used
as "using" statement
- Suppose we want to create our own project then we can create a namespace by using
"namespace" keyword.
Note: Mostly namespace name and project name are similar, but it is not mandatory.

C#.Net:
- C#.Net is a pure Object Oriented Programming language.
- C#.Net is a case sensitive.
- C#.Net is a type(datatype) safe language.
- In C#.Net every program execution will start from Main().
- Every statement should end with a statement terminator(;).
- For every Open delemeter "{" there should be a closing delemeter "}".
-----------------------------------------------------------------------------------
-----
Console Apps I/O Statements:
- Console is a class, which is already avaible in a namespace i.e. "System".
- This class is having methods for I/O operations like
- Write();
- WriteLine();
- Read();
- ReadLine();
- Clear(); etc.

Write():
- This method is used to display some message to the user.
- After display the control remains in the same line, so that it will display next
statements also in the same line.

WriteLine():
- This method is used to display some message to the user.
- After display the control jumps to new line.

Read():
- It is used to take the input from the user.
- This function is used to read the single charecter from the user, even if user
has eneterd multiple charecters.
- It will not read the exact value, rather it will read ASCII value.
- The return type of this function is "int".

ReadLine():
- It is also used to take the input from the user.
- This function is used to read multiple charecters or single charecter also.
- It will read exact value, entered by the user.
- The return type of this function is "string".

ReadKey():
- Used to read a special charecters like Enter, Backspace etc.

Clear():
- It is similar to clrscr() in C/C++ langauge. It is used to clear the screen.

Note:
- A solution is a collection of projects, a project can be anything like Console,
Windows, Web etc
- A Project is a collection of Items, an item can be anything like Class,
Interface, WinForm, Web Form etc.
- Only for the identification the class name and file names are similar but it is
optonal, but it is good programming practice.
- Function and Methods both are similiar in syntax, Both are used to execute the
logic whenever we call.
- The difference between function and method is, function will have "datatype" as
the return type, method will have "void" as the return type.
- Function is return something so that we have to store in a variable, but method
will not return anything.
- A Variable is used to store the values, the variable is also called as named
memory location.
- Every variable is assosiated with a datatype, which is used to specify the type
of the data the variable can hold.
- A Comment will not compiled and executed by the compiler.
- Comments will give us an easy way to understand the code.
- In C#.Net we have three types of comments
- Single Line - //
- Multi Line - /* Statements */
- XML Comments - ///
-----------------------------------------------------------------------------------
--------------------------------------
Type Casting:
- Converting one type of data into another type based on the requirement.
- C#.Net supports two types
1) Implcit type casting: No need to have seperate methods to perform type casting.
2) Explicit type casting: We need to use seperate methods to perform type casting.
- C++ type casting: It can be used to convert value to value (or) reference to
reference type.
- Parse(): It used to convert only string datatype to anyother value datatype.
Beacuse Parse method is assosiated with only value types like int,double,float,
char etc.
- Convert class: It is a class which is avaible in System namespace, which contains
different methods, those are used to convert any datatype into any other datatype.
Convert.ToInt32()
Convert.ToDouble()
Convert.ToChar()
Convert.ToBoolean() etc.

Note:
- The process of converting value type to reference type is called "Boxing".
- The process of converting reference type to value type is called "Unboxing".
-----------------------------------------------------------------------------------
-----
Steps to write the code in Notepad and Execute:
- Open Notepad and write the program.
- Save with an extension i.e. "*.cs"(C#)
- Open the Developer Command Prompt for Visual Studio 2022.
- Change the Directory to where file was existed.
- Compile the cs file by using a command "csc Filename.cs", It wil generate exe
file if we don't have errors.
- Execute by using "filename.exe".

Conditional Statements:
- The statments which can be executed based on conditions.
- Like every PL, C#.Net is also having all types of conditional statements like
- Simple If: If condition true, then execute
- If Else: If the condition is true then execute a block else execute another
block of statments
- Nested If else: An If else condition within another if else.
- If else Ladder: An if else condition followed by another if else
- Switch case: It is for writing more conditions by using cases.
switch(args)
{
case 0:
break;
:
:
:
defualt:
break;
}

Note: For every case label we need to mention break.


- Inlcude break for default statements as well.
-----------------------------------------------------------------------------------
-----
Loops: When we want to execute a set of statements repetedly.
- For Loop
- While Loop
- Do While Loop
- Nested Loop
- Foreach Loop
Note: When we know the range, then use for loop. If we don't the range then go with
while loop.
- If it is a while loop, it will get checks the condition from first iteration, if
it is a do while it checks the condition from second iteration.

Assignments:
- Fabonacci Series Program
- Palindrome Program
- Reverse given number
- Arm Strong Number
- Prime Number
above examples complete by using for and while loop?
-----------------------------------------------------------------------------------
-----
Arrays:
- An array is a variable which is used to store multiple values into it.
- An Array is a reference type.So that the values are stored in the heap memory.
- To represent an array we use "[]".
- An array wil store the data in key and value, where key is an index and it strat
from 0, value is depend on the type of array.
- Array is a type safe variable.
- The one disadvantage with arrays is "Fixed Length".
- In C#.Net we have 3 arrays
- Single Dimentional: Eigther single row or single column
- Multi Dimentional: Eigther multiple rows and column of equal or different
sizes also.
- Jagged Arrays: Every element is an array, with different size

- Jagged Array is also known as Arrays of Array which means every element in Jagged
Array is a Array only.
- To create a Jagged Array we will use [][].

Assignment:
- Single Dimentional: Copy the elements of array which is greater than 50.
- Multi Dimentional: Create a 2D array with dynemic data
- Jagged Array: Create Jagged array with the elements of 2D Array

Enums in C#.Net:
- It is a variable which contain named constants.
- It is not a class member so that we can declare it inside namespace directly.
- The advantage of declaring inside the namespace is, it can be available through
out the project in any class.
-----------------------------------------------------------------------------------
-----
- Before OOPS we use procedure oriented programming which means we can write
everything in functions/procedure. The limitations of procedure programming is
Reusability and security.
- C#.Net is a Pure Object Oriented Programming Language.
OOPS: Every PL if it is an OOPS, it must follow 4 features
- Encapsulation: Binding the member variables along with member functions, best
example for encapsulation is "class".
- Abstraction: Hiding the implmentation, providing the service.
In C#.Net, abstraction can be implemented in two ways
- Data Abstrction
- Functional Abstraction

- Polymorphism: One to many behaviours


- Static/Compile time/Early binding polymorphism
- Method Overloading
- Dynemic/Runtime/Late binding polymorphism
- Method overriding
- Method hiding

- Inheritence: Aquiring the properties of one class into another.


- Single Inheritence
- Multilevel Inheritence
- Heirarichal Inheritecne
- Multiple Inheritence
- Hybrid Inheritence

Class:
- A class is a collection of data members and member function.
- A class is a user defined datatype and object is a variable of class type.
- Inside the we can define 7 types of members
Data Members
- Variables
- Properties
- Indexers
Member Functions
- Methods/Functions
- Constructors
- Destructors
- Events
- A class is a logical entity, which contain similar type of members.
- Syntax:

class <className>
{
//members
//functions/methods
}

Object:
- An object is a physical existence. It is an instance of the class.
- syntax:
<className> <ObjName> = new <className>();
- "new" keyword is used to allocate the memory for the class and it's members.

Variable: It is a named memory location, which can be used to store the values.
- Only variables can store the data and no other member will not store data
anywhere.
- syntax: datatype varibleName = value;
- example: int x = 10;

Method/Fuction:
- Both are used to execute the logic, which can be used for reusability.
- Syntactically both function/method are similar.
<accessModifier> <returnType> <NameOfFun>([Optional parameters])
{
//Statements;
}
- But while implmentation, if the return type is void that is method, if the return
type is datatype i.e function.
- Method can't retutn anything it just used to execute the logic, but function will
return something to the calling place.
-----------------------------------------------------------------------------------
-----
Constructor:
- It is also similar to the function, but constructor is specially designed to
intilize the values for the class members.
- The constructor will be called automatically when an object to the class is
created.
- To create a constructor will follow two rules
- Constructor name should similar to class name
- Constructor doen't have return type including void also.
- A class can have any number of constructors but it should be overloaded.
- In C#.Net we have two categories of constructors
- Instance Constructors
- Default Constructor
- User-Defined Defualt Constructor
- System-Defined Defualt Constructor
- Parameterized Constructor
- Copy Constructor
- Private Constructor
- Static Constructors
- Static Constructor

Default Constructor:
- A constructor which will be created without parameters. If user has created it
then that is called "User-Defined Default Constructor".
- In a class if we are not having any constructor then system will create it's own
and intilize the default values.
- In that case if it is a value type it will assign "0" else it will assign "null".
- The limitation is for every instance it will maintain similar data.

Parameterized Constructor:
- A constructor with parameter is called as Parameterized constructor.
- We can maintain different values for every instance of the class.

Note:
- A class can have more than one constructor, but it should be different eighter in
number of parameters or in type of parameters.
- "this" keyword is also known as current class instance. which is used to access
the members of current class.

Copy Constructor:
- It is used to copy one complete object data into another.
- In Copy constructor, we have class name as the parameter.

Private Constructor:
- A constructor which will be created by using private access modifier.
- If a class is having private constructor we can't able to create an object
outside of the class.
- Private constructor is used to maintain secured information, and which is used to
set the restriction to the class that we can't create an instance of it outside.

Note: Above all the constructors are the instance constructors, which means for
every instance it will create a seperate memory.

Static Constructor:
- It will not create seperate memory for every object.
- Static members are created with the help of static keyword, And also if we define
any member in static function i.e. also a static member.
- Normal members can be accessed with the help of "Object name", if it is a static
member can be accessed with "class name".
- For the static members memory allocation is done first, but if it is an instance
member memory allocated only after creating an object.
- A constructor which will be created with a static modifier. It used to intilize
static members.
- A static constructor must be a parameter less.
- It can't have access modifier also including "public".
- We can execute static constructor only once i.e first execution of class.
- A class can have only one static constructor.

Note: In a class if we have Main() and static constructor, first static constructor
will gets executed later Main() will be called.

Destructor:
- It is used to deallocate the memory.
- To create it we use "~".
- We can have only one, it will called based on number of objects inside the class.
- In class if we have a destructor we don't have control on objects disposing.
- It would be called after the complete application execution completes.
- It must be parameter less.
-----------------------------------------------------------------------------------
-----
Inheritence:
- It is the process of aquiring properties of one class into another class.
- It is the proces of creating a new class from already existing class.
- Advantage of inheritence is "Reusability".
- In inheritence,the derived class object will have complete control on base class,
but base class is not having any control on derived class.
- The class which give code is called as "Base/Parent/Super" class, the class which
takes/aquire the properties is called "Derived/Child/Sub" class.
- Single Inheritence: If we have single base classes
- Single Inheritence: Creating single Base + Single Derived
- Multilevel: Creating different levels of inheritecnce
- Heirarichal: creating multiple child classes from single base
- Multiple Inheritence: If we have multiple base classes
- Multiple Inheritence
- Hybrid inheritence

Note: In Inhertence process always we will create object for child/derived


classses.
- To access the members of base class in derived class we use "base" keyword.
- In Inheritence process always when we create an object for derived class, the
derived class first call the base class constructor then it will look into derived
class constructor.

- Multiple inheritence is not possible with the help of classes, i.e. where we use
"Interface".
- If both base classes are having same function with same signature, while calling
that with the help of derived class object the compiler will get confused. This
situation is called "Ambiguity" situation of a compiler.

Polymorphism: One to many behaviours, Poly means many and morphism means
behaviours.
- It is a rule that the class should follow while creating the functions/methods.
- Static/Compile/Early binding polymorphism
- To achive static polymorphism we use "Method Overloading"
- Dynemic/Runtime/Late binding polymorphism
- To achive dynemic polymorphism we use "Method Hiding" and
"Method Overriding".

Method Overloading:
- Creating same function with different signature.
- A signature of a function includes number of parameters and type of parameters,
but method signature doesn't include return type.
- While calling the function at compile time itself we should come to know which
function will gets executed, i.e. reason we call it as "Static/Compile/Early
Binding polymorphism".
- It can be implmented in both base and derived classes.

Method Overriding:
- Creating same function with same signature in both base and derived classes.
- To work with method over riding we use "virtual" and "override" keywords.
- "virtual" can be given for base class members and "override" can be given for
"derived" class members.
- It is not mandatory to override a virtual function always and it is optional.
- If a function is not a virtual, we can't override it.

Method Hiding:
- Creating same function with same signature in both base and derived classes.
- In Method hiding we use "new" keyword for "Derived" class members.
- If the overriding of the base class member is mandatory, then we use Method
Hiding.
-----------------------------------------------------------------------------------
----
Abstract classes and Methods:
- A method which is not having any implmentation is called "abstract method".
- In a class if we have atleast one abstract method mark that class as "abstract
class".
- To create an abstract class or method we use "abstract" keyword.
- An abstract class can have both abstract and non abstract members.
- we can't able to instantiate an abstarct classes.
- It is mandatory to inherit a class from an abstarct class inorder to consume.
- Once we inherit it is must provide implmentation for base class abstract
members.
- While providing the implmentation for "abstarct function" in derived class we use
"override" keyword.
- Abstract classes can't used to implement multiple inheritence.

What is the difference between Method OverRiding and Abstarct functions?


What is the difference between Virtual and Abstarct keyword?
-----------------------------------------------------------------------------------
-----
Interfaces:
- Interface is a contract between itself and it's derived class. The contract is
interface will provide rules and regulations derived class must follow them.
- To create an interface we use "interface".
- It is similar to class, class can contain anything but interafce will contain
only abstract members.
- Every interface name should start with "I", it is coding standered.
- By default all the interface members are "public" and "abstract", so that no need
to specify expliciltly.
- We can't able to create instance of the interface.
- creating a child class is mandatory when we have an interface, once we create it
derived class must provide implementation for base interface.
- In Interface "override" keyword is not required.
- Multiple inheritance is achieved by interface.

Explicit Interface Implmentation:


- A class can be inherited from multiple base interfaces, but not the classes.
- Providing a seperate implementation for both base interface common member is
called explicit interface implmentation.

Assignment: Hybrid Inheritence


What are difference between abstract class and interface?
-----------------------------------------------------------------------------------
-----
Access Modifiers:
- It is used to provide the access for the class and it's members.
- C#.Net support 6 types
- private : Only within the class
- protected : Within Class + Derived classes as well
- internal : Within the Namespace/Project
- protected internal : Within Project + Another project derived class
- private protected (C#.Net 7.2) :Within class + Same project Derived
class
- public : Any where
Note:
- The default access modifer for a class is "internal".
- The deafult access modifer for a class member is "private".
- For a class we can have eighter internal implicitly or public explicitly, rather
than that we can't give anything for a class.
Indexers:
- An indexer is a class member, which is used to share the data from one class to
another class.
- An indexer is a special property that allows a class/struct to be accessed like
an array.
- A class can have any number of Indexers but it should be overloaded based on the
type parameter.
- Syntax:
<accessModifier> <returnType> this[argument]
{
set{}
get{}
}
- Example:
public object this[int x]
{
set{}
get{}
}

- set accessor is used to assign the value for class filed.


- get accessor is used to retrive the value form private filed.
-----------------------------------------------------------------------------------
---------------------------
Properties:
- A property is similar to filed, but properties are not used to store the data it
is used to transfer the data.
- It is mainly used to transfer the data from one class to another class.
- A property is used to share the data from the private variable to another
classes.

- Syntax:
<accessmodifier> <return type> <nameOfProperty>
{
set{variable = value;}
get {return variable;}
}

-Example:
public int PEmpID
{
//Used to assign data to the fileds
set
{
if (EmpID == 0)
EmpID = 101;
else
EmpID = value;
}
//Used to retrive the data from the fileds
get
{
return EmpID;
}
}
- A property will never store the data, it just used to transfer the data.
- In C#.Net we have 3 types of properties
- Read only : which contains only get accessor
- Write Only: Which contains only set accessor
- Read Write : Which contains both set & get accessor

Auto implemented properties:


- A property for which it is not required to provide implementation for set and get
accessor.
- If we have an auto implmented property, no need to create a private filed,
automaticlly tempporory filed will create at runtime and destroy once if it is
used.
-----------------------------------------------------------------------------------
---------------------------
Enums in C#.Net:
- It is also called as Enumeration.
- It is a variable which is used to store named constants like Weekdays, Colors,
Seasons,Months etc.
- Every constant in enum will be assigned with a value and defualt value will be
starts from "0".
- Enum is not a class member so that we can have outside of the class as welll.
public enum WeekDays{
Mon,Thu,Wed,Thur
}

Structures Vs Classes:
- Structure is the light version of classes

Structures
- It is a value type.
- It can't have defualt constructor.
- "new" keyword is not required.
- Inheritecne is not possible.
- A Structure can't be an abstract type.

Classes
- It is reference type.
- It can have any type of constructors.
- It is required to have a new keyword.
- It can be inherited.
- A Class can be an abstract type.

Asssignment: Practical usage of structures and classes?


-----------------------------------------------------------------------------------
---------------------------
Sealed Classes:
- A class for which it is not possible to inherit a new class is called sealed
class.
- These classes are mainly used for security.
- A sealed class can't have abstract/virtual members.
- Without having proper reason don't create any class as sealed class.
- In C# we have 2 ways can use "sealed"
- Sealed Class
- Sealed Methods
Note: Always sealed class is the bottom level class in the inheritence heirarichy.
- Sealed Method is used to stop the overriding functionality of a function.
- Always sealed keyword should be given for over riding functions.

Partial Classes:
- It is used to provide the flexibility to the devloper to share the work.
- A class for which we have an implementation in multiple files.
- To create a partial class we use "partial" keyword.
What is the use of partial methods?
What is the difference between sealed classes and abstract classes?
-----------------------------------------------------------------------------------
-----
Exception Handling:
- Error:Compilation Error, It can be identify by the compiler and gives an
appropriate message to the developer, so that developer will fix it.
- If developer is not follow proper syntax will get these type of errors.
- Exception: Runtime Error, It can be identified by Exception Handling machanism.
- When we have an exception in the application then the application can cause
abnormal termination.
- Bug: Can be identified at testing environment and identified by testers.

Exception Handling:
- In C#.Net we have two ways to handle the exception.
- Logical Exception Handling: can be handled by using conditions.Always as C#.Net
developer give the first priority for this.If we are not able to handle exceptions
using logical then go with try catch.
- try catch implementation:

Syntax:
try
{
//Statements where there is a possibility of getting exceptions.
//It will execute only one time.
}
catch
{
//It is used to catch the exception and give proper message.
//We can have any number of catch blocks
}
finally
{
//Suppose if we have execption or not, if we want to execute a block of code
then will use this block, and it is optional to have and also we have only one
finally block.
}

- There are two ways we can catch the exception


- Generic Catch: It will throw common execption message for all exceptions.
- Specific Catch: It will throw different exception message for every exception.
- In C#.Net we have exception classes like
- FormatException
- DivideByZeroException
- IndexOutOfRangeException etc.
Note: All these classes are having a base class i.e. "Exception", so that we can
use Exception class to handle exceptions.

Custom Exception:
- If the exception classes are not meet our requirement then wil create our own
exception class to display message to the user.

Step-1: Create a class and Inherit from Exception classs


Step-2: Override message property and give the custom message
Step-3: Use the custom class in catch block
-----------------------------------------------------------------------------------
-----
Class Librabries/Assembiles:
.Net = Framework(Class Librabries) + Runtime Environment(CLR)
*.exe
- A class which contain Main() after build it will generate exe file.
- These files can run itself
- These are not used for reusability.
- It contains code in machine code i.e. Native/Binary

*.dll
- A class which is not having Main() after build it will generate dll file.
- Can't run itself need to attach any of the executable file.
- Can be reused for multiple projects
- It contains the code in MSIL(Microsoft Intermediate Language).

Steps to add the reference of class librabry with executable projects:


-> Goto solution explorer -> rt.click on References -> Select the class librabry ->
and then keep using statement -> write the code.

Types of assembly:
- C#.Net is having two librabries
Private Assembly: It will maintain a seperate copy for every project.
Public/Shared Assembly: The assembly which is avaible in GAC folder is called
public/shared assembly, it will not maintain a seperate copy of dll in the project
folder.
- To convert a private assembly into public will follow few steps
- Generate the Strong Name Key
sn -k Arthematic.snk
- Register Strong Name key
[assembly: AssemblyKeyFile("D:\\C#6AM\ \ConsoleAppExamples\\
CLibArthematic\\bin\\Debug")]
- Install the librabry by using GAC Utility
gacutil -i CLibArthematic.dll
-----------------------------------------------------------------------------------
-----
Generics:
- These are general datatypes, which means we can create our own datatypes.
- These are introduces in C# 2.0v
- We can apply the generics concept for
- Functions
- Classes
- Interfaces
- Delegates etc.
- The main advatage is type safety. And also it can be used to avoid creating
multiple function while overloading.
- To work with Generics we know two things
- Place holder represented by "<>"
- Type parameter.
Note: Always type parameter should be enclosed within the place holder.

Object, Var and Dynemic:


Object: Itself it is a datatype and object is not a type safe member.
Var: It is an implicit varible, type can be decided at compile time.
Dynemic: It is also a type and the type can be decided at runtime.

Var vs Dynemic:
var:
- It was introduced with C# 3.0v
- It is an implicit typed variable, means datatype can be decided at compile time.
- Once we assign the value, we can't change the type.
- These member must to intilized.
- It can be used as local member, but it can't be used as global/parameters.

dynemic:
- It was introduced with C# 4.0v.
- Here type can be decided at runtime.
- We can chnage the value.
- Intilization is optional.
- It can be used as eigher local/global/paramter.
-----------------------------------------------------------------------------------
-----
Delegates:
- It is a function pointer, which can used to execute the functions.
- These are mainly used in "Event Driven Programming".
- Delegates are much more used in Winforms and ASP.Net Web forms development.
- Delegate is not a class member, eigther it can be created inside class or outside
the class.
- To work with deleate we follow 3 steps
- Create a delegate
- Instantiate a delegate
- Invoke a delegate
- There are two types of delegate
- Single Cast Delegate: Which is pointing single function.
- Multicast Delegate: Which is pointing multiple functions.

Note:
- While working with multicast delegate every fucntion should contain same
signature and also same return type i.e. "void".
- To add reference of a function we use "+=" and remove the reference we use "-=".

Anonymous Methods & Lambda Expressions:


- A method without name is called as anonymous methods.
- To create an anonymous method will use delegate keyword.
- Lambda expression is also an anonymous method.
- Mostly it can be used in LINQ Quries.
Note: These methods are required when we have a limited functionality in the
functions and that is executed with the help of delegate.

Generic Delegates:
- Func<>: It is used to execute "functions"(return type as datatype)
- Action<>: It is used to exeute "methods"(return type as void)
- Predicate<>: It is used to execute functions whose return type is "boolean".
-----------------------------------------------------------------------------------
-----
Collections:
- In C#.Net collections are the classes.
- These classes are used to store the unlimted values into a single
object/variable.
- Every collection internally runs with an algorithm, but as an OOPS no need to
learn algorithm becuase all the collections in C#.Net are the classes.
- All these collections are avaible in a namespace
- Normal Collections - System.Collections;
- Stack: LIFO
- Queue: FIFO
- ArrayList
- HashTable etc.
- Generic Collections - System.Collections.Generic;
- Stack<>
- Queue<>
- List<>
- Dictionaries<> etc.

Collections Types: Used to store collection of values.


- Normal Collections
- It will store any type of data and there is no type safety.
- We can store any number of value into the same variable.
- System.Collections
- Generic Collections
- It will store only perticular type values, we have typesafety
- We can store any number of value into the same variable.
- System.Collections.Generic

Limitation of Stack/Queue: We don't have control on the elements, which means we


can't able to insert/remove element based on the requirement.
Limitation of ArrayList: Remebering Index value is a limitation.
Hashtable: Hashtable collection will work with Hashing algorithm and it will
generate a value(Hashcode) and based on that values will be stored.

Limitation Advantage
Arrays - Fixed in size Type safety
Collections - No type safe Dynemic resizing
Generic collection - - Type Safe + Dynemic

- Generic collection classes are assosiated in "System.Collections.Generic"


- Stack<>
- Queue<>
- List<>
- Dictionaries<,> etc.
-----------------------------------------------------------------------------------
-----
Windows Forms Application:
- When it comes to User Interface point of view we have two types of applications
- CUI(Console/Command User Interface): Here we don't an image everything is a text.
- GUI(Graphical User Interface): Here the text is represented with an Image.

Console Windows Web Mobile


Presentation Layer (UI) - C#.Net HTML XAML
Businuss Layer(C#.Net) C#.Net C#.Net C#.Net C#.Net

Note: For most of the .Net applications Visual Studio will be generate presentation
layer code automatically.

- Windows forms appliaction is a GUI based application, which can also be called as
desktop applications.
- A winforms application will contain collections forms, here form is container
control which can contain multiple controls within it.
- A form is also a control and every control in winform is a class. All the classes
are assosiated in a namespace i.e. "System.Windows.Forms".
Note: In Winforms by default the designer code will be generated automatically.
- User defined form class is inherited from system defined "Form".

Event:
- An event is nothing but an action performed by user.
- In .Net Winforms, Web forms and mobile apps are works based on "Event Driven
Programming".
- Event will generate a function is called "Event Handler Method" and that function
will get executed with Delegate(EventHandler).
- In winforms every control is by default assosiated with one event, and this event
is fired when user double click on the control.

Note:
While giving the name property of the control we should follow naming convetion by
using Hungarian Notation, according to that
Button - btn
Label - lbl
TextBox - txt
RadionButton - rbtn
CheckBox - chk
DataGridView - dgv
ComboBox - cmb etc.
-----------------------------------------------------------------------------------
-----
Controls in Winforms:
- TextBox: Used to take the input
- Button: Execute the logic
- Label: Used to display static text

Validations for Mathematic Winforms App:


Validation - 1:
- Num1 and Num2 textbox should allow to enter only digits.
- To Identify whether the user entered data is a number or not we use and Event
"KeyPress".
- This event will contain a class i.e. KeyPressEventArgs which comes with two
properties like
- KeyChar: Used to Identify the key pressed by the user
- Handled: Is used to allow only accurate data.
Note: Char is structure which contain methods to identify the value is a number,
char, digit etc.

Validation-2: Num1 and Num2 textbox should not be empty


- To identify wether user has eneterd value in the textbox or not we use "Leave"
event.

Validation-3: When user click on Div button need to identify second number can't be
zero.

Validation-4: If user wants to reenter the data in the textbox and by clicking on
Backspace we have to handle it(Enable backspace button).
-----------------------------------------------------------------------------------
-----

- CheckBox: Selecting multiple options from the given group of options


- Radio Button: Used to select a single option from given group of options
- Grouping Controls: These are used to group multiple controls into single group
- Group Box
- Panel
- Tab Control etc.

GroupBox:
- It is having Text property
- It is not having scrolling facility
- It is occupying more design space.

Panel:
- We don't have Text property
- It comes with scrolling facility.
- It is not occupying more design space.
-----------------------------------------------------------------------------------
-----
- Collection Controls: Which are used to store multiple values
- ListBox
- DropdownList/ComboBox
- CheckBoxList etc

ListBox Example Validations:


- User should not allow to enter null values.
- User should not allow to enter duplicate values.
- Index Range must be in between 0 to highest index whille inserting and deleting
as well.

Menu controls and Dailouge Controls:


- Menu controls are used to display the Menu for the application
- There are two types of Menus
- Main Menu: We can have only one
- Context Menu: We can have any number of context menu and which can be
display when user right click on it.

Dailouge Controls:
- These controls are used to display dailogue boxes like
- Save Dailouge
- Font Dailogue
- Color etc.
-----------------------------------------------------------------------------------
-----
ADO.Net:
- It is a middle ware technology which is used to interact with frontend and
backend applications.
- ADO.Net will be used to communicate with different datasources.
- To communicate like that ADO.Net is having different data providers like
- Sql Client -> Sql Server Database - Microsoft
- Oracle Client -> Oracle Server Database - Microsoft
- ODBC Client -> Any DB - Third Party
- OLEDB Client -> Any DB - Third Party
- Borland Client -> Any DB - Third Party

ODBC: Open Database Connectivity


OLEDB: Object Linking Embeed Database

ADO.Net Objects:
- Connection Object
- Command Object
- DataReader Object
- DataAdapeter Object etc.

Sql Client Data Provider:


- It will contain classes and these classes are used to communicate with Sql Server
DB.
- It contain classes like
- SqlConnection
- SqlCommand
- SqlDataReader
- SqlDataAdapter
- SqlCommadBuilder
- All the above classes are avaible in a namespace i.e. System.Data.SqlClient.

What are the different approches in ADO.Net to connect with DB?


- ADO.Net supports two approches
- Connection Oriented Approch
- Disconnected Oriented Approch

CRUD - Create/Insert, Read, Update, Delete


Commands - Insert,Select,Update,Delete
-----------------------------------------------------------------------------------
-----
- Quries
- Constraints
- Stored Procedure
- Views
- Functions
- Joins
- CTE
- Triggers

Connection Oriented Approch in ADO.Net:


- While working with connection oriented architecture open and close the connection
manually.
- Till the query gets executed the connection should be in opened state.
- To work with connection oriented architure we need to follow few steps
- Establish the connection by using "SqlConnection" object
- Prepare the query and pass it to the backend by using "SqlCommand"
- Open the connection
- Execute the Query
- Close the connection
- "ConfiguarationManager" is a class which can be used to interact with
Configuration file like app.config (or) web.config.
- This class is avaible in a namespace i.e. "System.Configuration".
- To execute the query by using command object we have 3 query executing methods
are available
- ExecuteNonQuery()
- It can be used for action quries like "Insert/Update/Delete"
- It can return the number of rows affected in the type int.
- ExecuteReader()
- It can be used for NonAction query like "Select"
- It used to return a table/row/column and the return type is
SqlDataReader type
- ExecuteScalar()
- It can be used for NonAction query with aggregate functions
- It used to return a single value of object type.
- Connection object is used to establish the connection, and open/close the
connection.
- Command object is used to pass the query to the backend and also take care
executing the query by using query executing methods
- Parametrized query: When we want to work with action queries/Stored Procedure
this approch can be used.
- In this approch we use a class i.e. "SqlParameter".
-----------------------------------------------------------------------------------
-----
Limitation of Quiries in Frontend:
- If we have written quiries at frontend application, it will cause unnecasary
compilation.
- No security: Everyone who are working on project they know what DB and tables are
avaible to build the application.
- Sql Injuction Attcks: At the time passing the query from frontend to backend
if some injuction was happend by the hacker, then the db server will give that
result.

Stored Procedure:
- It is a set of pre compiled sql statements.
- All the stored procedure will be written in backend application only.
- It is not possible to perform Sql Injuction attacks.

Syntax:
create procedure <nameOfProc> [Parameter]
as begin
....Sql Statements...
end

Exec <nameOfProc>

Note: Every parameter in Sql should start with "@"

Examples:
Select SP:
create procedure SelectEmps
as begin
select * from Employee
end

SelectEmps

Insert SP:
create procedure InsertEmp @Eno int,@Ename varchar(max),@Salary money,@Job
varchar(max),@Dname varchar(max)
as begin
insert into Employee values(@Eno,@Ename,@Salary,@Job,@Dname)
end

InsertEmp 106,'Srikanth',58745,'Trainer','Competency'

Delete SP:
create procedure DeleteEmp @Eno int
as begin
delete from Employee where Eno=@Eno
end

DeleteEmp 102

UpdateSP:
create procedure UpdateEmp @Eno int,@Ename varchar(max),@Salary money,@Job
varchar(max),@Dname varchar(max)
as begin
update Employee set Ename=@Ename,Salary=@Salary,Job=@Job,Dname=@Dname where
Eno=@Eno
end

UpdateEmp 106,'Cherry',58795,'Developer','IT'

SP with Ouptut Parameter:


create procedure GetSal
@Eno int,@Salary money Output
as begin
select @Salary=Salary from Employee where Eno=@Eno
end

-- Declare a Variable of Type Int. Should match with SP's Output parameter
DECLARE @Salary money

-- Don't forget OUTPUT keyword


EXEC [dbo].[GetSal] 105,@Salary OUTPUT

-- Printing the Output


PRINT @Salary
-----------------------------------------------------------------------------------
-----
DataReader:
- It will work with connection oriented architecture only.
- It is readonly object.
- It is forward only stream memory.

When the result set will be closed?


- The result set will be closed in two scenarios
- When the data reader closed
- When the connection closed.
Reading the data reader:
DR[0] or DR["Eno"] -> 101
-----------------------------------------------------------------------------------
-----Disconnected Architecture:
- In this approch we need not to open/close the connection manually.
- DataAdapter object will takes responsibility to open/close the connection.
- While working with this approch first will get the table by using select
statement and keep it in frontend app and perform CRUD Operations.
- Once we get the data the connection wil be closed automatically.
- To work with this we use classes like
- SqlConnection
- SqlDataAdapter
- DataSet/DataTable

What is DataSet?
- It is an in memory object which can be used to represent the data in frontend
application
- It can be working with Disconnected model.

Architecture of DataSet:
- DataSet
- Tables
- Table1
- Rows
- Row1
- Row2
- Columns
- Col1
- Col2
- Table2

3=> 101 Srikanth 12345 Trainer IT

DS.Tables[""].Rows[2].Columns["Salary"] => 12345

DataGridView Control:
- This control provides powerful and flexible way to display the data in a tabular
format.
-----------------------------------------------------------------------------------
-----
Extension Methods in C#.Net:
- These are the methods which can be added to the existing classes/structures
without midifying/compiling the source class.
- To create an extention method we use static classes and method we can define as
an extension method should be a static methods.

Async and Await:


- It is a new concept introduced in C# 5.0 which can be used to implement parallel
development in application.
- await keyword is applied for the functions which can take more time for
processing
- Every await function sould be in a async function.

Nullable types:
- These are data types, especially value types which can be handle null values.
- To create this we use "?" for any valid value types.

Reflection:
- It is the process of identifying metadata of a class or structure.
- To work with this we use a class i.e. "Type".

Serialization:
- It is process of converting objects into streams, so that the data will be stored
into memory, file or DB. The reverse process of serialization is deserialization.
-----------------------------------------------------------------------------------
-----
ADO.Net Limitations:
- Developer has to learn all the query languages based to the Datasource.
- Queries are combination of Sql + OOPS.
- ADO.Net quries are not type safe.
- It doen't provide intellisence.
- It doesn't give error, rather it gives exceptions.

LINQ:
- It stands for Language Integrated Query.
- It contain uniform syntax, which can be used to communicate with any type of
datasource.
- It means even if the data source is changed no need to change query language.
- And also LINQ can be written in pure OOPS.
- Based on data source LINQ can be defined in following ways
- LINQ to Objects
- LINQ to SQL
- LINQ to Entity
- LINQ to ADO.Net DataSet
- LINQ to XML etc.
Note: LINQ quries are executed internally with the help of "ADO.Net Disconnected
Approch".

syntax:
var Obj = from <aliasName> in <collection> [clauese] select <aliasName>;

Example:
var Obj = from x in Emps select x;
LINQ to Object: It can be used to communicate with Objects like Arrays, Collections
etc.
-----------------------------------------------------------------------------------
-----
Advanced and New C#.Net 8.0 Concepts:
Ref and Out
- Both are used to return multiple values to the calling place.
- But if it is ref, even if we are not having implmentation at the time calling
what ever the values we intilized those are going to be used and intilizing those
values are mandatory.
- But if it is out, it is must to provide values at the time of implementation and
at the time of calling it is optional to define them even.

Tuple:
It is used to return multiple statetes to the calling place without using ref and
out keywords.

Deconstructors:
It is used to provide the access for the private field that can be accessed outside
of the class.
--------------***********------------------

You might also like