0% found this document useful (0 votes)
37 views10 pages

Key Point of C#

Uploaded by

naveen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views10 pages

Key Point of C#

Uploaded by

naveen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Key Points of C#

Reference Sites:
https://www.completecsharptutorial.com/basic/

https://www.tutorialsteacher.com/csharp/csharp-tutorials

https://www.javatpoint.com/c-sharp-tutorial

CLR:
Common Language Runtime
.NET CLR is a run-time environment that manages and executes the code written in
any .NET programming language. It converts code into native code which further can be
executed by the CPU.

To write the code using any dot net supported programming languages such as C#, VB,
J#, etc. Then the respective language compiler will compile the program code and
generate something called Microsoft Intermediate language (MSIL) or Intermediate
language (IL) code. For example, if the programming language is C#, then the compiler
is CSC and if the programming language is VB, then the compiler will be VBC.
This Intermediate Language (IL) code is half compiled code i.e. partially compiled code
and cannot be executed directly by the Operating System. To execute this Microsoft
Intermediate language (MSIL) or Intermediate language (IL) code on your machine,
the .NET Framework provides called Common Language Runtime (CLR) which takes
the responsibility to execute your Microsoft Intermediate language (MSIL) or
Intermediate language (IL) Code.

The CLR takes the IL (Intermediate Language) code and gives it to something called JIT
(Just-in-Time) Compiler. The JIT compiler reads each and every line of the IL code and
converts it to machine-specific instructions (i.e. into binary format) which can be
executed by the underlying Operating System.

Main components of CLR:

Common Language Specification (CLS):


It is responsible for converting the different .NET programming language syntactical
rules and regulations into CLR understandable format. Basically, it provides the
Language Interoperability. Language Interoperability means to provide the execution
support to other programming languages also in .NET framework.

Language Interoperability can be achieved in two ways :

1. Managed Code: The MSIL code which is managed by the CLR is known as the
Managed Code. For managed code CLR provides three .NET facilities:

2. Unmanaged Code: Before .NET development the programming language like .COM
Components & Win32 API do not generate the MSIL code. So these are not
managed by CLR rather managed by Operating System.

Common Type System (CTS):


Every programming language has its own data type system, so CTS is responsible for
understanding all the data type systems of .NET programming languages and converting
them into CLR understandable format which will be a common format.
There are 2 Types of CTS that every .NET programming language.

1. Value Types: Value Types will store the value directly into the memory location.
These types work with stack mechanism only. CLR allows memory for these at
Compile Time.
2. Reference Types: Reference Types will contain a memory address of value
because the reference types won’t store the variable value directly in memory. These
types work with Heap mechanism. CLR allots memory for these at Runtime.

Garbage Collector:
It is used to provide the Automatic Memory Management feature. If there was no
garbage collector, programmers would have to write the memory management codes
which will be a kind of overhead on programmers.

JIT (Just In Time Compiler):


It is responsible for converting the CIL (Common Intermediate Language) into machine
code or native code using the Common Language Runtime environment.
C#:
C# is a strongly typed object-oriented programming language. C# is open source,
simple, modern, flexible, and versatile.
Key characteristics of C# language include:

1. Modern and easy


2. Fast and open source
3. Cross platform
4. Safe
5. Versatile
6. Evolving

Data Types:
C# is a strongly typed language. It means, that you cannot use variable without data
types. Data types tell the compiler that which type of data is used for processing.
C# provides two types of data types:
1. Value types
2. Reference types.
Value Types:
Value type data type stores copy of the value, data type is a value type if it holds a data
value within its own memory space. It means the variables of these data types directly
contain values.

The following data types are all of value type:

 bool
 byte
 char
 decimal
 double
 enum
 float
 int
 long
 sbyte
 short
 struct
 uint
 ulong
 ushort

Reference types.
Reference type data types stores the address of the value, unlike value types, a
reference type doesn't store its value directly. Instead, it stores the address where the
value is being stored. In other words, a reference type contains a pointer to another
memory location that holds the data.

The followings are reference type data types:

 String (String is immutable. It means once we assigned a value, it cannot be


changed. If we change a string value, then the compiler creates a new string object in
the memory and point a variable to the new memory location)
 Arrays (even if their elements are value types)
 Class
 Delegate

Variable:

A variable refers to the memory address. When you create variable, it creates holds
space in the memory that is used for storing temporary data. As you know about c# data
types, each data type has predefined size.

Sample : <data type> <variable name> = <value>;


int num = 100;

boxing:

Boxing is the process of converting a value type to the object type or any interface type
implemented by this value type. Boxing is implicit.

Samples: int i = 10;


object o = i; //performs boxing

ArrayList list = new ArrayList();


list.Add(10); // boxing
list.Add("Bill");

All the reference types stored on heap where it contains the address of the value and
value type is just an actual value stored on the stack.

Example: int i is assigned to object o. Object o must be an address and not a value
itself. So, the CLR boxes the value type by creating a new System. Object on the heap
and wraps the value of i in it and then assigns an address of that object to o. So,
because the CLR creates a box on the heap that stores the value, the whole process is
called 'Boxing'.

Unboxing:

Unboxing is the reverse of boxing. It is the process of converting a reference type to


value type. Unboxing extract the value from the reference type and assign it to a value
type.

Unboxing is explicit. It means we have to cast explicitly.

object o = 10;
int i = (int)o; //performs unboxing

Invalid Conversion
int i = 10;
object o = i; // boxing
double d = (double)o; // runtime exception
Valid Conversion
int i = 10;
object o = i; // boxing
double d = (double)(int)o; // valid

OOPS – Object oriented programming system:

Object-oriented programming is about creating objects that contain both data


and methods. The four basic principles are there:

Encapsulation: Encapsulation is the process of hiding irrelevant data from the user,
It is hide unwanted code within a capsule, Encapsulation is used Access Specifiers to
hide its members from outside class or interface, those are five
1. Public
2. Private
3. Internal
4. Protected
5. protected internal

Public: it can be accessed by other class members that are initialized outside the class
and even outside the namespace

Private: Restrict the member variable or function to be called outside of the parent
class you can store or retrieve the value from private access modifiers using get the set
property on public access modifier.

Protected: The protected access specifier hides its member variables and functions
from other classes and objects. This type of variable or function can only be accessed in
child class. It becomes very important while implementing inheritance.

Internal: Internal access specifier allows a class to expose its member variables and
member functions to other functions and objects in the current assembly. The variable or
classes that are declared with internal can be access by any member within application.
It is the default access specifiers for a class in C# programming.

Protected internal:

Private protected:

Abstraction: Abstraction is just opposite of Encapsulation. it is a mechanism to show


only relevant data to the user, It is used to display only necessary and essential features
of a properties and methods (object) to outside the Class.
Inheritance: Its allows you to access members of base class in child class. It
enables you to create a child class that can access and use all the functionality of
its base class. This way you can keep common variable and functions in a base class
and use them as many times as you want to inherit child class. Code reusability makes
your program simpler and efficient.
 Abstraction inheritance – its should be override in child class.
 Virtual inheritance - its should be override or not be override in child class.
 Sealed class – its can not be inherit any other classes.
 Interface to be used for to overcome multiple inheritance.
Types of inheritance:
1. Single inheritance
2. Hierarchical inheritance
3. Multi-level inheritance

Polymorphism: Polymorphism provides the ability to a class to have multiple


implementations with the same name of method, inherited properties or methods
in different ways across multiple abstractions.
.

There are two types of polymorphism in C#:

 Static / Compile Time Polymorphism - you bind a function with an object


during compile time. It is also called early binding. In static polymorphism,
Function Overloading gets implemented
 Dynamic / Runtime Polymorphism - It is also called as Late Binding or
Method Overriding or Dynamic Polymorphism. In dynamic polymorphism, we
override base class function using virtual & override keywords.

Function Overloading: a function works differently based on parameters. A single


function can have different nature based on a number of parameters and types of
parameters.

Function Overriding: In dynamic polymorphism we override a base class function using


virtual or override keyword. Method overriding means having two or more methods with
the same name, same signature but with different implementation.

Method hiding: you can hide the implementation of the methods of a base class from
the derived class using the new keyword.

Interface:
Interface can have methods, properties, events, and indexers as its members. But
interfaces will contain only the declaration of the members. The implementation of the
interface’s members will be given by class who implements the interface implicitly or
explicitly.
In C# doesn’t support multiple inheritance, but by using this interface we can overcome
that problems.
By default all the members of Interface are public and abstract.

Difference between interface and abstraction


https://www.geeksforgeeks.org/difference-between-abstract-class-and-interface-in-c-
sharp/

Constructor:

Reference: https://dotnettutorials.net/lesson/constructors-csharp/

Types of Constructor:

Default Constructor – system defined / user defined


Parameterized Constructor
Copy Constructor
Static Constructor
Private Constructor

Types of classes:
Abstract class
Partial class
Sealed class
Static class

Reference:
https://tutorialslink.com/Articles/Different-types-of-classes-in-c-programming/1167

Solid design principles:

Reference:
https://dotnettutorials.net/course/solid-design-principles/

single responsibilities principle


Open Closed principle
Liskov substitution principle
Interface segregation principle
Dependency inversion principle

Readonly, constant and static readonly


Reference: https://www.c-sharpcorner.com/UploadFile/c210df/difference-between-
const-readonly-and-static-readonly-in-C-Sharp/

Object Pooling:

Reference: https://www.codeguru.com/csharp/object-pooling-in-c/
https://www.c-sharpcorner.com/article/object-pooling-in-net/

Ienumerable and iEnumerator

Reference: https://www.c-sharpcorner.com/UploadFile/0c1bb2/ienumerable-
interface-in-C-Sharp/
https://www.c-sharpcorner.com/UploadFile/219d4d/ienumerable-vs-ienumerator-
in-C-Sharp/

Difference between: ienumerable vs list

https://www.c-sharpcorner.com/forums/ienumerable-vs-list

yield keyword:
https://www.c-sharpcorner.com/UploadFile/5ef30d/understanding-yield-return-in-
C-Sharp/

Difference between: Ienumberable vs iquerable


https://dotnettutorials.net/lesson/differences-between-ienumerable-and-
iqueryable/

Dependency inversion
Reference: https://dotnettutorials.net/lesson/dependency-inversion-principle/

Difference between var and dynamic:


https://www.c-sharpcorner.com/blogs/difference-between-var-and-dynamic-in-c-
sharp2

What is dependency injection and what are the types? This is design pattern
Constructor injection
Property injection
Method injection
https://dotnettutorials.net/lesson/dependency-injection-design-pattern-csharp/

exception handling and types of exception:


https://www.c-sharpcorner.com/article/exception-handling-in-C-Sharp/

N-Tier architecture and layered architecture in c#


https://medium.com/@hidayatarg/n-tier-layer-architecture-in-c-15b8fe97283c

Design pattern reference site:


https://dotnettutorials.net/course/dot-net-design-patterns/

Difference between sync and async method in c#


Reference site:
https://www.sitepoint.com/asynchronous-programming-using-async-await-in-c/
https://www.c-sharpcorner.com/article/async-and-await-in-sc-sharp/

Shallow copy and deep copy


https://www.tutorialspoint.com/what-is-shallow-copy-and-how-it-is-different-from-
deep-copy-in-chash

https://dotnettutorials.net/lesson/shallow-copy-and-deep-copy/

You might also like