C#.
NET
Day-1: Introduction.
Introduction:
(C Lang: loops, Array, Function, Pointer.
SQL: 100% DML, DDL, TCL, PLSQL.
Web Design: HTML, CSS, JAVASCRIPT).
What is .NET:
.net is framework created by Microsoft company in 2002. It has multiple technologies like C#.NET, ASP.NET, ASP.NET
MVC, ASP.net Core.
The founder of .net is Anders Hejlsberg.
(in 1990 there is ASP technology which use only drag and drop but in 2002 .net was come and after that ASP.Net)
(Future Scope: Desktop Application, Console base application, Web application, Mobile application, Gaming application:
Unity)
.net is bunch or collection of libraries.
C#.NET: It is a backend language.
ASP.NET: Frontend language.
Features of .Net:
1. Simple Programming Language.
2. Platform Dependent before 2016 ASP.NET Core – platform independent.
3. OOPS C#.NET- 80% similar as java, C++ but 20% features are different.
4. Multithreaded Programming Language- Gaming – Unity company 1st time use C#.
5. Secured.
6. High performance.
7. Type Safe.
8. Interoperability.
.NET:
C#.NET, ASP.NET, ADO.NET, ASP.NET MVC, ASP.NET Core MVC, ASP.NET Web API.
C#.NET:(all are Microsoft product)
For frontend: ASP.NET
For backend: C#.NET
For deployment: Azure Cloud
For database: SQL Server
C#.NET:
Current Version is 13.
Current Version is 9.
What is .NET Framework:
.NET is a programming framework created by Microsoft that developers can use to create application more easily.
A framework is a bunch of code that the programmer can call without having to write it explicitly.
It is collection of libraries.
Day-2: CLR, Datatype, Variable, Operator & program structure.
What is CLR (Common Language Runtime) in .NET Framework:
It is the foundation of .NET Framework.
It acts as execution engine for the .NET Framework.
It manages the execution of programs and provides a suitable environment for programs to run.
It provides a multi-language execution environment.
Execution Process of C#.NET:
When code is executed for 1st time:
The CIL code is converted to a native code to the operating system.
This is done at runtime by Just-In-Time (JIT) compiler present in CLR.
The CLR converts the CIL/Assembly code to the machine lang. code.
Once this is done. The code can be directly executed by CPU.
Development process of C#.NET:
CLR- Common Language Runtime
Datatypes-
Which type of data is store for particular variable.
Types of Datatypes:
1. Primitive Datatype: int[2/4byte], char[1byte], float[4byte], short, double[8byte], byte, Boolean, long.
(int size 2 byte or 4 bytes)
For ex: int a=10; char ah=’A’,’B’;
Real life ex: Age calculator, Currency calculator, Menu driven calculation.
2. Non-Primitive: string, array, structure and union.
For ex: int a [] = {10,20}; String x =” Aarti”;
Real life ex: Small applications.
(Why integer is in primitive type: It has fix size 2 or 4 byte)
Variables-
Variable is a container which holds the values.
Variable is assigned with the datatype; without datatype we cannot define any variable.
For ex:
variable---A = 10---→value
Types of Variables-
1. Local: Access only within the particular class/block or only scope.
(only within the class inside single block)
2. Global: Access entire application/everywhere in our program.
3. Static
4. Instance
Operators-
Operators are the symbol which perform any mathematical operation.
Types of operators:
Unary op, Comparative op, Arithmetic op (+-*/%), Assignments op, Bitwise op, ternary op, Logical op.
Program structure of C#.NET:
What is? public static void Main(String[] args):
It is the entry point of C#.NET program.
Public: It is access modifier.
static: It is keyword.
void: It is return type.
Main: It is static method.
(String[] args) : It is command line arguments.
Console.WriteLine(); :
Console: It is class present in System namespace. (WriteLine()is a static method directly access by Console classname)
WriteLine(): It is static method present in console class.
Note: (Add Class write program remove internal before class name save code go in properties then startup project. set
program name save it and run 2nd code).
Day-3: Control statement: Decision Making (if else, else if ladder, switch case)
Control Statement:
1. Decision Making: if else, else if ladder, switch case.
2. Iteration/ Loops: for, while do while.
Decision Making:
1. If else:
If condition is true then execute the if block
If condition is false then execute the else block
Syntax:
For ex:
2. Else if ladder:
Syntax:
3. Switch case statements:
Syntax:
For example:
Day-4: Control statement: Loops (for, while, do while, nested for)
Iteration loops:
1. For loop:
In for loop, we know the start and end point.
Syntax:
2. While loop:
It is entry control loop, there is no ending point.
Syntax:
3. Do while loop:
It is exit-control loop, the statement presents in do while loop execute at least one time then check condition.
Syntax:
4. Inner and outer for loop (nested for loop):
Syntax:
Palindrome or reverse number:
Tasks:
Tasks1:
Day-5: Functions: (Call by value, call by reference, out parameter), Array (Intro and 1D array)
Function:
Function is a block of code which perform the specific task. when function is called then function is executed.
Function call:
Note: If more than 1 classes are present in our program that time in which class our public static void main
method will present that class name is use for save the program.
Method is also same like function but within a class. without object we cannot call method.
By using static keyword in method name that time we can directly call that method:
By using classname.methodname ..Sample.add()
Call by value & call by reference:
In call by value: Original value cannot modify.
In call by reference: Original value can be modified after calling.
Use ref keyword.
Must be initialized the original value before calling.
ref keyword & out keyword:
In ref keyword, before calling initialization is must.
In out keyword, no need to initialized the original value before calling.
Array:
1. Array is the collection of same type of data.
2. It is a fixed sized we cannot increase or decrease at the runtime.
3. Index through we can easily access that data directly.
4. Array always start from 0 (Zero) index and end with size-1.
Advantages of array:
1. Random Access
2. Easy of sorting
3. Easy of searching
4. Code optimization
Disadvantages of array:
1. Fixed sized
2. Same type of data
3. Waste memory
4. For insertion and deletion is worst case.
Types of arrays:
1. 1D Array
2. 2D Array
3. Multi-Dimensional array
4. Jagged Array
How to declare 1D array:
1. int [] a = new int[size-of-array];
2. int [] a = {10,20,30,40,50};
3. int [] a = new int [] {10,20,30,40,50,60};
4. int [] a new int [5];
a [0] = 23;
a [1] = 45;
a [2] = 12;
a [3] = 28;
a [4] = 76;
Task:
Day-6: Array: (2D Array, multi-d array and Jagged array)
2D Array:
2D array are also called matrix array.
Syntax:
Multi-Dim Array:
Syntax:
For ex:
Jagged Array:
It is an Array of array.
In jagged array we know the rows size but don’t know the columns size.
Syntax and Ex:
Ex:
Day-7: String Introduction
What is String:
1. String is the collections of character.
2. Sequence of array. represent array 0 index R, 1 index o.
3. Non-primitive data type.
4. String is class in C#.NET.
5. String is Immutable Objects.
6. Object is a parent class of string class.
Ways to declare String in C#.NET:
Two ways to declare String:
1. String class: A. String x= “Hii”; B. string x= “Hii”; C. String x = new String(“Hii”)
Or by using String class a.(class) string x="hii"- [literals] , b. String x = new string("hii")- [object] , c.(datatype)
string x="hii" .
2. StringBuilder Class:
What is string intern pool:
SIP is Special Memory Location Which we can Store the String literals only.
String intern pool present inside the heap area.
If we create literals:
Note: Always string literals is better than new keyword or object. (String class in C#.NET is sealed).
Deep explanation of SIP:
Interview Question:
What is string?
Why string object are immutable?
How many ways to declare string?
String literals new keyword difference?
What is string intern pool?
Day-8: String and String builder
What is the difference between == operators vs .Equals() methods:
== Operator compare references.
.Equals() Method compare the values(content)
Note: Object is the parent of string class and all predefine classes.
What is the diff between Equals() in object class and in String class:
String object are immutable object.
StringBuilder s1 = new StringBuilder(“Hello”);
S1.Append(“India”);
CW(s1);
StringBuilder create the mutable object.
Que. How many no. of characters you can insert or store in that string Builder.
Ans: By using Capacity() method (s1.Capacity); 16 characters.
old capacity * 2.
Que. Which method is use for reduce capacity or remove extra space.
Ans: s1.Capacity =s1.Length;
Diff between Capacity & .Length method:
1. .Capacity : Calculate how many characters we can store in that string builder.
2. .Length : Calculate the number of characters present in that string builder.
3. .Clear : Clear the data of string builder.
4. .Remove(2,4) : It remove the characters between the given indexes.
5. .Equals("Welcome") : It compare the contents/ values of string builder.
Diff bet String and StringBuilder:
Note: As compare to String StringBuilder if fast.
Task:
Day-9: OOPS1 (Introduction, class, method & object)
Object Oriented Programming system/structure:
It is a way to create or maintain our program. In oops all are “real world programming”
Oops is called the heart of C#.NET. It is very imp topic.
OOPS – C#, java, PHP, python
Why C# 100% Object oriented programming?
ANS: NO, 1. Because “Wrapper Class”. 2. Its supports primitive datatype directly. -means we can use int32 for int
System.Int32
System.Boolean
Which is pure?
ANS: SMALLTALK is a 1st pure object-oriented programming language.
Pillers of oops:
1. Class and Object:
2. Inheritance.
3. Abstraction.
4. Polymorphism.
5. Encapsulation.
Class:
1. Class is the collections of objects.
2. Class is not the real-world entity.
3. Class is the logical entity.
4. Class does not occupy the memory.
5. Class is a blueprint or template.
Method:
Method is a block which perform a specific task. (behaviour of object)
Object:
1. Objects occupy the memory (in heap area).
2. Object are the instance of the class.
3. Object is the physical entity.
4. Object is the real-world entity.
5. object consist the behaviours and states of object which are write in class that are access by creating object.
6. we can create the object by using new keyword.
EX: Animal dog = new Animal(); Commented [AD1]: Ref.variable
Commented [AD2]: keyword
Commented [AD3]: object
Day-10: OOPS2 (Constructor & its types)
Constructor:
1. Constructor is same like a method.
2. Its name must be same name as its class name.
3. There is no explicit return type in constructor. (void or int)
4. Constructor is automatically called when object is created.
Advantage of constructor:
To initialized the object.
Types of constructors:
1. Default Constructor
2. Parameterized Constructor: We can pass the parameters.
3. Copy Constructor (there is no use of it): Copy the value of one object to another object.
Que:
What is constructor?
Advantage?
Why we can create constructor?
Day-11: OOPS3 (Inheritance and its types)
Inheritance:
What is Inheritance:
It is a relationship or parent & child relationship or blood relationship.
Child class acquire all the properties and behaviour of the parent class as well as current class also.
Advantage:
1. Code Reusability
Disadvantage:
1. Tight Coupling
Types of Inheritance:
1. Single Inheritance
2. Multilevel Inheritance
3. Multiple Inheritance
4. Hierarchical Inheritance
5. Hybrid Inheritance
Single Inheritance:
In a single inheritance here is one parent and one child.
Multi-level Inheritance:
In a multiple inheritance here is multiple levels of classes.
If grandparent have show() and parent have get() after then child access both show() , get() & its own also.
Multiple Inheritance:
It has many parent classes and single child class.
In multiple inheritance occurred ambiguity problem and diamond problem.
Multiple inheritance cannot support in C#.NET
Hierarchical Inheritance:
It has one parent class and many child classes.
It is also called opposite of multiple inheritance.
Here is a draw back.
Hybrid Inheritance:
It is a combination of any two types of inheritance except single.
Combination of multilevel and hierarchical inheritance.
Day-12: OOPS4 (Interface_ Why Multiple inheritance is not possible)
Why Multiple inheritance is not Supported in C#?
1. Ambiguity Problem:
2. Diamond Problem:
Is there any another option to achieve multiple inheritance in C#?
Ans: Yes, Interface can use for achieve multiple inheritance.
Abstraction-
Abstraction is hides the internal details and shows only functionality to the user.
For ex: all electrical devices, Computer memory, ATM machine.
Ex:
What are abstract methods:
There is no implementation of the method we can declare the method only.
Definitions of Interface:
1. We can achieve the abstraction.
2. Interface through we can achieved 100% abstraction.
3. Achieved multiple inheritance.
4. Interface contains only abstract method, not implementation.
5. Interface method default public + abstract. (It contains static and default method in C# 8.0)
6. We cannot create the object of interface but we create the reference of interface by creating the object of class.
Syntax of interface:
For Ex:
Day-13: OOPS5 (Keywords_ this and access specifiers/modifiers and base keyword)
Keywords:
this keyword:
this keyword is referred to the current class instance variable.
this keyword uses for conclusion between your local variable name and your instance variable name.
Way of use of this keyword:
1. this variable:
this variable is used to initialized the current class instance variable.
2. this method:
If you don’t use this keyword, compiler automatically add this keyword while calling the method.
3. this constructor:
Its reuse the constructor.
Ex:
Access modifiers/Specifiers:
Accessibility or scope of any variables and methods.
Public: Accessible everywhere.
Private: Accessible only within the class.
Protected: Accessible only child class/ or use inheritance only.
Internal: Accessible only same namespace, not outside namespace.
Protected + internal: Accessible only child of another namespace.
base keyword:
base keyword is use only in inheritance.
If parent class and child class have same fields then confusion between which data is access then base keyword.
Day-14: Static Keyword_ Sealed_ Abstraction
Static keyword:
Static keyword is used for memory management.
Way to use static keyword:
Static variable: Common property for every object.
No need to create object of the class. We can directly call by its class name.
Static method: (method is always by default private) no need to create object of the class. we can directly call the by
class name.
Note: We can call static method from non-static method but we cannot call non-static method from static method.
We can also call static method from static method.
Static class: All data of static class is always static.
All the variable and methods are static.
Sealed keyword:
It provides the restriction. It uses only with class.
Restriction of inheritance.
Abstraction:
Its hides the internal details and shows only functionality to the users.
How many ways to achieve abstraction:
1. interface – 0 to 100% abstraction
2. abstract class – 0 to 100% partially abstraction
Abstract class:
Diff between interface and abstract class:
Interface Abstract class
100% abstraction. 0 to 100% partiality abstraction.
Default public + abstract. Abstract keyword before the method declaration is
compulsory.
Implements all the abstract method present in Inherit all the methods ‘extends’.
the interface.
Interface contains only abstract methods not Abstract class contains abstract methods as well as
method body. non-abstract methods.
We can achieve multiple inheritance. It is not possible to achieve multiple inheritance.
hierarchy inheritance is achieved.
Day-15: Polymorphism_ Encapsulation
Polymorphism:
Poly: many Morphisms: forms
Polymorphism means one thing can behave multiple operations.
For ex:
Types of polymorphism:
1. Compile time poly or Static polymorphism
2. Runtime poly or Dynamic polymorphism
Compile time polymorphism: (Static)
Handle by compiler
Method overloading:
If a class has multiple methods having same name but parameter list is different is known as method overloading.
Rules:
1. Same class.
2. Multiple methods same name, parameters different.
3. Change the datatype if parameter list is same.
4. Change the sequence if the datatype is same.
Que 1: if I want to achieve method overloading using return type. Is it possible?
Ans: No, not possible.
Que 2: Is it possible to overload main method?
Ans: Yes, by changing parameter.
Que 3: if you have two main method then which is execute?
Ans: where string array(String[] args) is present that main method is execute. But you want execute another main
method yes by Program.Main(); no need to provide class name because Main() is static method call by Main();
Runtime polymorphism: (Dynamic)
Method overriding:
If a child class suppose there is one method that is get() and same to same method declare in the parent class. It is
known as method overriding.
To change the definition of the parent class.
Rules:
1. Different class.
2. Inheritance compulsory. (Is-A relationship)
3. Method name, Parameter, datatype, sequence is same but class is different.
Note: In parent class use virtual keyword before method name, and in child class use override keyword before method
name.
Que 1: Automatic promotion?
Ans: It means datatype can automatically promoted from one type to another.
Que 2: Method overriding is possible by access modifiers?
Ans: Yes.
Encapsulation:
Encapsulation is a data hiding
Rules:
1. Declare all the variables are private.
2. Apply getter and setter to set and get the data in it.
Wrapping data and methods together into the single unit.
Day-16: Exception Handling1(introduction)
Exception:
Any unwanted or unexcepted events ocures During the execution of the program.
TierpucExce, AccidentOccurExep, TrafficFoun, PetrolKhatam.
Exception means Any unwanted or unexcepted event occur during the execution of the program its known runtime
exception.
So normal flow disturb.
Find out the alternate way to handle that exception.
What is the diff. Exception and Error: (Imp)
Types of Exception:
1. Compile time exception(chacked):
2. Runtime exception(unchacked):
Types of Error:
1. Runtime Exception/ Error
What is diff bet. Compile time and run time Runtime Exception:
Ex:
Try and catch block:
Syntax:
Syntax:
Day-17: Exception Handling 2 _ finally block _ throw keyword
Exception Handling:
Note: In Single try block we can write multiple catch block.
Finally keyword:
1. Finally block is always executes whether exception is handle or not.
2. Finally block follows try and catch block.
Note: you can use finally block with try block without catch but not with catch block without try block.
throw keyword:
throw keyword is used for custom exception/ user defined exception.
Day-18: File Handling _ File IO _ Day 1
File IO: Input and Output Operation
File:
A file is a collection of data sorted in a disk with a specific name and a directory path.
Name: abc.txt
Directory path: C:/programFile/abc/txt
For ex: notepad file, word file, rtf file, xlsx .docx.
File Handling:
File Handling allows to store / retrieve data on permanent storage.
FILE*f1
Some classes provided by C# for performing the file handling Operation:
1. FileStream
2. BinaryWriter
3. BinaryReader
4. StreamWriter
5. StreamReader
6. FileInfo
7. DirectoryInfo
File.Exists(path): It is use for showing file is present on given path or not.
Note: All file related classes are present in System.IO namespace.
Day-25: Multithreading 1 _ Introduction
Multitasking:
Multiple tasks work at a same time it is known as multitasking.
Types of multitasking:
1. Process based multitasking.
2. Thread based multitasking.
Multiprocessing:
Multithreading:
Multiple threads work at the same time.
Big process.
Ex:
Games and Animations.
For ex:
Life cycle of Thread class:
Thread born :-> runnable state :-> running state :-> dead state.
Que 1: thread life cycle?
Que 2: if thread go dead state that will be born again?
Ans: No, never.
Thread Priorities:
According to these priorities OS allocate the processor
Windows does not support priorities.
Sometimes output maybe vary.
Prevent threads executions methods:
Sleep() :
Specific amount of time threads hold or pause.
Thread.Sleep();
Day-25: Multithreading 2 _ Yield _ join _ method
Yield() :
Which stops the current executing thread and its give us chance to provide other waiting thread.
Thread.Yield();
Note:
It provides the hint by the thread scheduler and thread schedular accept the hint then output will be correct.
If thread schedular ignore the hint then output may be varied.
Join() :
It means until 1st thread terminate then other thread will run.
It allows one thread to wait for another thread's completion, ensuring proper synchronization.
Thread.Join();
Synchronization:
If at the same time multiple user work on same source that time synchronization occurs.
It is only one process or thread accesses the critical section of the program. All the other threads have to wait until the
critical section is free before they can enter it.
Thank You!!!