C# PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Framework:

A framework, or software framework, is a platform that provides a foundation for developing software applications. Think of it as a
template of a working program that can be selectively modified by adding code. It uses shared resources – such as libraries, image
files, and reference documents – and puts them together in one package. That package can be modified to suit the specific needs of
the project. With a framework, the developer can add or replace features to give new functionality to the application.

Types of frameworks:

With the huge variety of programming languages out there, naturally, you’ll find that there are a large number of frameworks
available. Each of these frameworks is used to solve different problems that come up in the process of software development. They’re
used in many industries, including web development, data science, and more. Here, we’ll go into some of the broader categories of
frameworks with examples of specific frameworks within them.

Back-End Web Frameworks:

Back-end web frameworks, or just web frameworks, are the most commonly used programming frameworks. But what are web
frameworks? Web frameworks assist developers in making web applications and dynamic websites. These frameworks completely
transformed the way web development is done, speeding up the entire software development process by automating common tasks for
web developers, like providing database access, session management, and page templates. Instead of building websites using HTML,
JavaScript and CSS, back-end frameworks use programming languages to interact with a database to generate content. This means that
this work is hosted on a server, hence why it’s the back-end portion. Common back-end web frameworks include.

Django – an open-source Python web development framework. It was designed to “help developers take applications from concept
to completion as quickly as possible”. A popular choice due to its speed, security, and scalability.

Framework Programming Language Famous Use Cases

Instagram
Django Python Pinterest
Coursera

MySpace
ExpressJS NodeJS GeekList
Storify

Deltanet Travel
Laravel PHP Neighborhood Lender
MyRank

ZendDesk
Ruby on Rails Ruby Shopify
GitHub
Mapme
CakePHP PHP Educationunlimited
Followmy Tv

Front-End Frameworks:
Where back-end web frameworks are loaded on a server, front-end frameworks are executed in a user’s browser. They allow web
developers to design what the users see on the website, things like the management of AJAX requests, defining file structures, and
styling the website’s components.

The most common front-end frameworks are:


 Angular JS – a front-end JavaScript framework. It was developed and is supported by Google. Features like two-way data binding
and dependency injections have greatly helped reduce development time, making this a popular option in the web development
community.
 React – another front-end JavaScript framework developed by the team at Facebook to help them make changes to the site’s code
easily. One of its more popular features is the use of virtual DOM, allowing for more seamless site performance and ensuring that
high-load applications render faster.
 Bootstrap – a front-end CSS framework that is a collection of reusable HTML, CSS, and Javascript code. Having all this code pre-
defined in a downloadable file allows for developers and designers to save time creating fully-responsive websites.

Mobile Development Frameworks:

With the rise of mobile rapidly gaining traction, mobile development frameworks have seen an equally impressive uptick. Like their
desktop counterparts, mobile development frameworks give developers a structure that supports the mobile app-building process.
They can be split into two different types, native mobile apps (meaning the app would be built for either Apple or Android) and cross-
platform frameworks (resulting in an app that’s compatible with any phone). Common mobile development frameworks are:

 Flutter – A cross-platform app framework that forms native code, meaning you can use one programming language and code base to
create an app for both Apple and Android. It was developed by Google and is free and open-source.
 React Native – A cross-platform app framework that also forms a native code developed by the team at Facebook. It was created with
both JavaScript and ReactJS programming languages and comes with ready-made components that can save developers time as they
don’t have to create elements from scratch.

What makes a good framework?


A good framework is:
 Simple to understand, consistent, and easy to implement.
 Has a default behaviour that is useful and does something. It should not contain redundant code that doesn’t perform a function.
 Uses all the best practices from the past, with the ability to evolve in the future.
 Allows the developer to build components that are reusable.
 The flow of control is handled by the framework – meaning the framework takes control of the order of processing, not the caller.
 It can be extended – adding additional code – to provide different functionality.
 It contains default framework code that can’t be modified, only extended.
Why to use framework? –
a) No Need to write code from scratch

b) Save Time

c) In this, security features are already made, due to which the application is more secure and we do not need to worry about security.

d) Many features library, helpers, controllers are already present which make software development task easy like making URL SEO
friendly.

e) In this, different sections are made for all the tasks, due to which it is very easy to write and understand the code.

f) Testing and debugging is easy.

g) Different Sections for different tasks.

h) Clean code

i) Lot of in build tools

Components of. Net Framework:-


1. CLR (Common Language run-time)

2. FCL (. Net Framework Class Library)

3. .Net Languages
1. CLR (Common Language Run-time):- It works like a virtual machine, and executes all the languages. CLR translates the source
code into byte code, which we call CIL (Common Intermediate Language) or MSIL (Microsoft Intermediate Language). And after
that converts this CIL code or MSIL code into native code by JIT compiler at run-time.

2. FCS (Framework Class Library):-FCL is Microsoft's standard library, and it is a reusable, class, interfaces library. It can

be used for web-based, Windows GUI applications and ASP. Net application, used to develop console-based application goes.
Different types of application
1. Embedded Systems
2. Windows applications (also called 'Desktop applications')
3. Web Applications
4. Web Services
5. Console applications

Embedded Systems

When we save a name, address and other information in to our Mobile Phone or Digital Diary, you know How it gets saved in it?
Nothing but which is a small computer program 'Embedded' into a chip in the device inside the mobile phone or digital diary known as
Embedded Systems.

Windows applications
Windows Applications is a form based standard Windows, Microsoft word; Paint is example to the Windows application, and also
called 'Desktop applications'.

Web Applications

A web site is also called 'web Applications'. A web application is a collection of web pages hosted on a special computer called 'web
server'. Web server can be located anywhere and visitors can be located anywhere. It will work through Browsers (EG. Internet
Explorer, Mozilla, Netscape).

Web Services

Web services are web applications that give services to other applications through the internet, example Google search engine, Yahoo
Search engine etc. which allows other applications to delegate the task of searching over the internet.

Console Applications

Console applications runs inside the command prompt i.e. DOS window, It is a light weight program and which is used commonly for
test applications.

Web Application

a) A web application or web app is a type of software program that is created to accomplish a specific task.

b) This web application is stored on the web server and whenever the user or client sends a request, this application is executed
on the client's web browser.

c) Like any other computer software or application, this application provides its user with an environment where data is entered
by the user.

d) This user is able to perform different types of tasks.

e) Different scripting languages are used to create these web applications.

f) This includes server-side scripting languages such as: PHP, ASP, etc.

g) This includes client-side scripting languages such as: HTML, jQuery, JavaScript, etc.
Role of web server and web browser

Object Orientation
The object-oriented approach, however, focuses on objects that represent abstract or concrete things in the real world. These objects
are first defined by their character and their properties, which are represented by their internal structure and their attributes (data). The
behavior of these objects is described by methods (functions).
MSIL (Microsoft Intermediate Language)
Whenever you compile a C# program, direct machine code is not generated. Rather a pseudo code is generated, which is called MSIL.
It is similar to the byte code of java. Which is later converted and machine code is generated.

CLS (Common Language Specification)


In .NET framework, different languages have to follow some common rules to work together. These rules are defined by CLS. But
this is possible only when all the languages are .NET compatible. If you want to create a program that can use other languages, then
your program should be CLS compatible.

First C# Program
C# can be used in a window-based, web-based, or console application. To start with, we will create a console application to work with
C#.

Open Visual Studio installed on your local machine. Click on File -> New Project... from the top menu, as shown below.

From the New Project popup, shown below, select Visual C# in the left side panel and select the Console App in the right-side panel.
In the name section, give any appropriate project name, a location where you want to create all the project files, and the name of the
project solution.

Program.cs will be created as default a C# file in Visual Studio where you can write your C# code in Program class, as shown below.
(The .cs is a file extension for C# file.)

Every console application starts from the Main() method of the Program class.

Example displays "Hello World!!" on the console


(1). Every .NET application takes the reference of the necessary .NET framework namespaces that it is planning to use with
the using keyword, e.g., using System.Text.
(2). Declare the namespace for the current class using the namespace keyword, e.g., namespace CSharp.FirstProgram
(3). We then declared a class using the class keyword: class Program
(4). The Main() is a method of Program class is the entry point of the console application.
(5). String is a data type.
(6). A message is a variable that holds the value of a specified data type.
(7). "Hello World!!" is the value of the message variable.
(8). The Console.WriteLine() is a static method, which is used to display a text on the console.

Note:
Every line or statement in C# must end with a semicolon (;).
Output:

Hello World!!

C# Keywords & Types of Keywords


C# contains reserved words that have special meaning for the compiler. These reserved words are called "keywords". Keywords
cannot be used as an identifier (name of a variable, class, interface, etc.).

Modifier Keywords
Modifier keywords

abstract

async

const

event

extern

new

override

partial

readonly

sealed
Modifier keywords

static

unsafe

virtual

volatile

Access Modifier Keywords


Access modifiers are applied to the declaration of the class, method, properties, fields, and other members. They define the
accessibility of the class and its members.

Access
Modifiers Usage
public The Public modifier allows any part of the program in the same assembly or another assembly to access the type
and its members.
private The Private modifier restricts other parts of the program from accessing the type and its members. Only code in
the same class or struct can access it.
internal The Internal modifier allows other program code in the same assembly to access the type or its members. This is
default access modifiers if no modifier is specified.
protected The Protected modifier allows codes in the same class or a class that derives from that class to access the type or
its members.

Statement Keywords
Statement Keywords

if
else
switch
case
do
for
foreach
in
while
break
continue
default
goto
return
Statement Keywords

yield
throw
try
catch
finally
checked
unchecked
fixed
lock

Method Parameter Keywords


Method Parameter Keywords

params
ref
out

Namespace Keywords
These keywords are applied with namespace and related operators.

Namespace Keywords
using
. operator
:: operator
extern alias

Operator Keywords
Operator keywords perform miscellaneous actions

Operator Keywords
as
await
is
new
sizeof
typeof
stackalloc
checked
unchecked
Access Keywords
Access keywords are used to access the containing class or the base class of an object or class.

Access keywords
base
this

Literal Keywords
Literal keywords apply to the current instance or value of an object.

Literal Keywords
null
false
true
value
void

Type Keywords
Type keywords are used for data types.

Type keywords
bool
byte
char
class
decimal
double
enum
float
int
long
sbyte
short
string
struct
uint
ulong
ushort

Contextual Keywords
Contextual keywords are considered as keywords, only if used in specific contexts. They are not
reserved and so can be used as names or identifiers.

Contextual Keywords
add
var
dynamic
global
set
value

Contextual keywords are not converted into blue color (default color for keywords in visual studio)
when used as an identifier in Visual Studio. For example, var in the below figure is not in blue,
whereas the color of this is the blue color. So var is a contextual keyword

Query Keywords
Query keywords are contextual keywords used in LINQ queries.

Query Keywords
from
where
select
group
into
orderby
join
let
in
on
equals
by
ascending
descending
Example: Use Keyword as Identifier

using System;

public class @class


{
public static int MyNum { get; set; }
}

public class Program


{
public static void Main()
{
@class.MyNum = 100;

Console.WriteLine(@class.MyNum);
}
}

C# Class and Objects


A class is like a blueprint of a specific object that has certain attributes and features. For example, a car should
have some attributes such as four wheels, two or more doors, steering, a windshield, etc. It should also have
some functionalities like start, stop, run, move, etc. Now, any object that has these attributes and functionalities
is a car. Here, the car is a class that defines some specific attributes and functionalities. Each individual car is an
object of the car class. You can say that the car you are having is an object of the car class.

Object-oriented programming, a class defines some properties, fields, events, methods, etc. A class defines the
kinds of data and the functionality their objects will have.

Define a Class
class Student
{

A class can contain one or more constructors, fields, methods, properties, delegates, and events. They are called
class members. A class and its members can have access modifiers such as public, private, protected, and
internal, to restrict access from other parts of the program.
Add different members to the Student class

Field: A class can have one or more fields. It is a class-level variable that holds a value. Generally, field
members should have a private access modifier used with property.

Eg.

class Student
{
public int id;

You might also like