Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C# Materila

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

EBENEZER GROUP OF INSTITUTIONS

EBENEZER MANAGEMENT COLLEGE

DEPARTMENT OF COMPUTER APPLICATIONS


V SEMESTER BCA COURSE

TITLE: C# AND DOT NET FRAMEWORK


[AS PER NEP SYLLABUS]
BENGALURU NORTH UNIVERSITY

COMPILED BY
PROF. HARLIN SHEEBA M
Unit-1
Introduction to .Net Technologies

Introduction to Web Technologies


Web Technology is a means by which computers communicate with each other over the internet. The
methods by which computers communicate with each other over the internet through the use of markup
languages and multimedia packages is known as web technology. Web technologies refer to the various
tools, languages, and frameworks used for creating and maintaining websites and web applications.

Three Core Technologies of Web Development


HTML (Hypertext Markup Language):
HTML provides the structure and content of web pages. it uses a set of markup tags to define the structure
of a document and its elements, such as headings, paragraphs, lists, links, images, and more. HTML is
used to create the content of web pages and is the foundation for building web sites and applications.

CSS (Cascading Style Sheets):


CSS provides the presentation and styling of web pages. It allows to separate the presentation of a web
page from its content, making it easier to maintain and update the look and feel of a web site. CSS can be
used to define colours, fonts, spacing and other visual elements ofa web page, and can be applied to
multiple pages, making it easy to maintain a consistent look and feel across a web site.

JavaScript: JavaScript
It is a high-level programming language that is used to add dynamic interactivity to web pages. It can be
used to create interactive effects, such as dropdown menus, pop-ups, and more. JavaScript can also be
used to create complex applications. such as online shopping carts, social networks and more. JavaScript
is an essential part of modern web development and is supported by all major web browsers.

Important Terms of Web Technologies


The World Wide Web (WWW or Web) refers to a system of interlinked hypertext documents that are
accessed through the internet. It was created by Sir Tim Berners-Lee in and has since grown into a vast
network of information, services, and communication connecting billions of people and devices around
the world.
Sir Tim Berners-Lee had written the three fundamental technologies that remain the foundation Of today's
web in 1990.
HTML: The language used to create a hypertext format document is HyperText Markup language.
URL: Every web page is identified on Internet by its address, also called Uniform Resource Locator.
Examples: https://www.google.co.in/, https://www.amazon.in/ etc., 3.
HTTP: The hypertext format document is transferred on the Web using HyperText Transfer Protocol.
It allows for the retrieval of linked resources from across the web.

Universal Resource Locator (URL)


URL stands for Uniform Resource Locator. It is the unique address used to identify a specific web page
or resource on the World Wide Web (WWW or simply the Web).
URLs serve as a reference to the location of a web resource and are used by web browsers to access and
retrieve web pages, images, videos, and other types of content.
Example: "https://www.example.com/about" is a URL that refers to the "about" page of the
"www.example.com" domain.

IP Address
An IP (Internet Protocol) address is a unique numerical label assigned to every device connected to the
internet. An IP address consists of four numbers separated by periods such as 192.168.1.1.
There are two main types of IP addresses: IPv4 (Internet Protocol version 4) and IPv6 (Internet Protocol
version 6). IPv4 uses 32-bit addresses and is the most commonly used type. while IPV6 uses 128-bit
addresses and is gradually being adopted to replace IPV'4 due to the depletion of available IPv4 addresses.

HTTP (Hypertext Transfer Protocol)


It is a communication protocol used to transmit data over the internet. It is the foundation of data
communication for the World Wide Web. When we visit a website, a web browser sends an H ITP request
to the server hosting the website. The server then sends an HTTP response.
which includes the web page and any other resources (such as images or videos) required to display the
page in a browser. HTTP is stateless, meaning that each request and response is treated as an independent
transaction and the server not keep track of previous requests from the same client. However, cookies and
sessions can be used to maintain state across multiple requests. HTTP is an essential component of the
web and plays a crucial role in the exchange of information between browsers and servers.
How HTTP Works?

HTTPS (Hypertext Transfer Protocol Secure)


It is an extension of the HTTP protocol that adds an extra layer of security. When we access a website
using HTTPS, the communication between our browser and the server is encrypted, making it difficult
for anyone to intercept or steal the data being transmitted.
This encryption is achieved through the use of SSL (Secure Sockets Layer) or its successor, TLS
(Transport Layer Security).
It provides an added level of security for sensitive information, such as login credentials and read it card
numbers, by encrypting the data transmitted between the browser and server.

Web Browsers
A web browser is a software application that allows users to access, retrieve and display information on
the World Wide Web (WWW). It is the primary tool used by individuals to access and interact with
websites and Other online resources.
Examples: • Internet Explorer
• Mozilla Firefox
• Google Chrome
• Microsoft Edge
When a user enters a URL into the browser, the browser sends an HTTP request to the server hosting the
website. The server then sends back an HTTP response.
It also provides a user-friendly interface and additional features, such as bookmarks, tabs, and history, to
make navigating the web easier and more efficient.

Web Server
A web server is a computer that stores, processes, and delivers website files to web browsers. A web server
is a computer system capable of delivery web content to end users over the internet via a web browser. A
web server is software that runs on the web site hosting Server computer. Its main purpose is to serve web
pages, which means it waits for requests from web browsers (also known as clients) and responds by
sending the required data back.

Client Server Communication


when request is made by one computer then that computer is called client and when the request gets served
by another computer then that computer is called server.
Web Page and Web Site
web Page
A webpage is a document written in HTML and can be viewed on any web browser. It is contained within
the web server, which can be accessed by entering the URL for that web page, and once it is loaded, it
appears on the user's web browser. Each webpage is linked with a unique URL; hence two pages cannot
have the same URL. The Web consists of files, called Web pages (documents). A web page may contain
text, graphics, and hyperlinks to other web pages and files. Moreover, it is mainly used to provide
information to the user in text, images, etc.
Example: https://www.amazon.in/gp/css/homepage.htm Web Site A website is a collection of several web
pages. These pages are linked together with hyperlinks.

website
A website has a unique domain name, and we can access it by entering that domain name in the URL A
website is a collection of webpages that are under one domain. One website will have several webpages
like Home, About Us, Contact Us, Services, Products, etc. All of these pages together make up a website.
In other words, a webpage is an independent page of a website.
Example: https://www.amazon.in
Types of website
Static Website: A static website contains Web pages with fixed content. Each webpage displays the same
information to every user. Static sites are the most basic type of website and are the easiest to create.
Example: Common examples of static websites include resume websites, portfolio websites, brochure
websites, one-off landing pages, and other informational or read-only sites.

Dynamic Website: A dynamic website is a website that displays different types of content every time
a user view it. This display changes depending on a number of factors like viewer demographics, time of
day, location.
Example: login & signup pages, application & submission forms, inquiry and shopping cart pages.

Types of Dynamic Websites


Server-Side Dynamic Website or Webpage: These web pages are created using Server-side scripting.
These pages are changed when they are visited or viewed. Some examples of server- side pages are login
pages, submission forms, shopping carts, etc. Various scripting languages such as PHP, ASP.Net, JSP, etc.
can be used for server-side scripting.

Client-Side Dynamic Website or Webpage: These web pages are created using Client-side scripting.
These pages get changed in response to actions that occur within that page, such as mouse or keyboard
action. Scripting languages such as JavaScript, Dart, etc., can be used for client-Side scripting.

Web Development
Web development refers to the process of designing, creating, and maintaining websites and web
applications. It encompasses various aspects of web design, programming, and technology to build
functional, visually appealing, and user-friendly websites and web applications.

Web Development can be classified into two ways:


1. Front End Development
2. Back End Development
Front End Development:
The part of a website that the user interacts directly is termed as front end. It includes everything that users
experience directly text colours and styles, images, graphs and tables, buttons, colors, and a navigation
menu. Front-end development focuses on the client-side of web development.
which involves creating the user interface and user experience of a website. This includes elements such
as the layout, design, and interactions on a page.
Technologies Used in Front End : HTML CSS, and JavaScript are the languages used most for Front End
development.

Back End Development:


Back end is the server side of a website. It is the part of the website that users cannot see and interact.
It is the portion of software that does not come in direct contact with the users. It is used to store and
arrange data. This includes databases, server-side scripts, and APIs, For example, a back-end developer
may create a script that takes the user's input from a form, stores it in a database, and then sends an email
to the user to confirm the submission.
Technologies Used in Back End: PHP, Java, C++, Python, Node.JS, JavaScript, Ruby, GO, C#.NET.
HTML Basics
HTML stands for Hyper Text Markup Language and is used to create Web pages. Tim Berners-Lee is
known as the father of HTML.
The first available description of HTML was a document called "HTML Tags" proposed by Tim in late
1991; the latest version of HTML is HTML5
It is useful for creating Web pages HTML describes the structure of a Web page HTML consists of a series
of HTML elements HTML elements tell the browser how to display the content.

HTML Versions
HTML has progressed and evolved over time, new versions of the language have been released to
introduce the new features.
Initially, the HTML was released in the year of 1993 and developed by Tim Berners-Lee in 1990.
The current HTML5 version has gained so much popularity because of its newly added features in it.

Features or Characteristics of HTML


•Easy to Learn and Understand: HTML is quite easy to understand as HTML is mainly comprised of
tags and elements only. Since it is easy to learn. we can develop websites easily using HTML.
• Flexibility: It is a markup language, so it provides a flexible way to design web pages along with the
text.
• Linkable: It facilitates programmers to add a link on the web pages, so it enhances the interest of
browsing of the user.
• Platform Independent: It is platform-independent because it can be displayed on any platform like
Windows, Linux, and Macintosh, etc.
• Extensive Features: We can add images, links, sounds, videos, gifs„ etc., using HTML to make the
website more attractive and interactive.
• Markup Language: HTML is not a programming language as it is only concerned with presenting the
information on the web. It is not used to program any logic but to give structure and semantically meaning
to our website. Though we can link JavaScript code to it which is a programming language.
• Case Insensitive: HTML is a case-insensitive language, which means we can use tags either in lower-
case or upper-case.
• Language Support: HTML can support various other languages like JavaScript, Ruby, PHP, Perl, and
many more. You can also able to run embed python during the runtime.

Advantages and Disadvantages HTML


Advantages of HTML
• HTML is a lightweight markup language.
• HTM is easy to learn, easy to understand language to develop web pages.
• HTML is one of the most popular and widely used languages that contains numerous, resources
and has a big community.
• HTML is supported by all the browsers.
• HTML can be integrated with multiple languages like Java Script, Python, Java„ etc.
• HTML is open-source and completely free.
• The web standard for HTML is maintained by World Wide Web Consortium (W3C).
• HTML is optimal for various frequently changing browser windows.
• The HTML is an independent free language.
• The HTML community is huge therefore developer can get necessary help from forums and
discussion websites.

Disadvantages or HTML
• Limited Interactivity: HTML provides only limited interactivity, and its static nature can make
it difficult to create dynamic and interactive web pages. To overcome this limitation web
developers often have to use additional technologies such as JavaScript and CSS.

• Complexity: As the web has evolved, HTML has become more complex, with a growing number
of tags and attributes that web developers need to learn and understand. This complexity can make
it challenging for new web developers to get started with HTML. and it can also lead to poorly
designed and inconsistent web pages.

• Browser Compatibility issue: Different web browsers can interpret HTML differently, and this
can lead to compatibility issues that can affect the appearance and functionality of web/ pages. To
overcome these issues, web developers need to test their web pages in multiple browsers and make
adjustments as needed.
Structure of HTML
Heading tags
Any document starts with a heading. You can use different sizes for your headings.
HTML also has six levels of headings, which use the elements <h1>, <h2>, <h3>,
<h4>, <h5>, and <h6>. While displaying any heading, browser adds one line before
and one line after that heading.

Scripts
In web development, the scripts are used to create client-side features and server-side features for a web
application. These features work together to create a whole application that appeals to end users and work
efficiently.
▪ A Script is a list of instruction to tell another program what to do.
▪ A script does not need the compilation step but it is interpreted one by one at runtime.
▪ The scripting languages are interpreted languages which directly executed without requiring
to be complied into machine language program
▪ Examples : VBScript, JavaScript, ASP, PHP etc.

Features of Scripting Language


▪ Easy to Learn and Use : They are easy to learn and implement.
▪ Open-source and Free : Most of the scripting languages are open-sourced, which means
there are no limits on who can utilize scripting languages. Anyone around the world can use
and contribute to their development.
▪ Powerful and Extensible : Scripting languages are powerful (in terms of application) enough
so that the necessary tasks can be accomplished with the scripts.
▪ Cross-Platform : Scripting languages offer another significant advantage: they are cross-
platform, as they execute on a remote server or in the visitor's web browser. This means they
don't require any additional software to run, and they can used with any browser on any
operating system and platform.
▪ Less Memory Requirements : Unlike programming languages. they are not compiled,
Instead, they are interpreted.
▪ Runtime Execution: an application can be configured and modified while it is running using
a system that permits code to be executed during runtime. This capacity is, in fact. the most
important feature that makes scripting languages so important in most applications.
▪ Safe and Secure: scripting languages have been designed with security in mind. A scripting
language does not allow any illicit operations to be performed from the script and even stops
native code from accessing information stored in the script.

Types of Scripting Languages


The server side includes code that runs in the background and is not visible to users.
Client side server involves any code that runs on a browser and the user can interact with on the website.

1. Client Side Scripting languages


▪ Script that executes on the user’s computer system called client.
▪ It is a small program or a set of instruction that is inserted into a web page and processed
within client browser instead of we server.
▪ HTML document can be stored in separate external file called external script.
▪ The script files are sent to the client machine from the web server when they are requested
▪ Then client web browser executes the script and displays the web page.
▪ EX: VBScript, JavaScript, JQuery.
2. Server-Side Scripting languages
▪ It is a program that is executed on the server side when the user requests information.
▪ When the client requests the page, web server reads it and then locates the file on disk which
loads into memory and ask the script engine to process the script code in server.
▪ Server-side scripting helps to develop an interactive website that communicates with the
database.
▪ It can be used to perform more complex tasks that need a lot of processing power.
▪ Ex: PHP, JavaScript, Perl, Python

Advantages of Client-side Scrips:


▪ Allow for more interactivity by immediately responding to users’ actions.
▪ Execute quickly because they do not require a trip to the server.
▪ May improve the usability of Web sites for users whose browsers support scripts.
▪ Can give developers more control over the look and behavior of their Web widgets.
▪ Can be substituted with alternatives (for example, HTML) if users’ browsers do not support
scripts.
▪ Are reusable and obtainable from many free resources.
Disadvantages of Client-side Scripts:
▪ Not all browsers support scripts, therefore, users might experience errors if no alternatives
have been provided.
▪ Different browsers and browser versions support scripts differently, thus more quality
assurance testing is required.
▪ More development time and effort might be required (if the scripts are not already available
through other resources).
▪ Developers have more control over the look and behavior of their Web widgets; however,
usability problems can arise if a Web widget looks like a standard control but behaves
differently or vice-versa.

Advantages of Server-side Script:


▪ User can create one template for the entire website.
▪ The site can use a content management system which makes editing simpler.
▪ Generally quicker to load than client-side scripting.
▪ User is able to include external files to save coding.
▪ Scripts are hidden from view so it is more secure. Users only see the HTML output.

Disadvantages of Server-side Script:


▪ Many scripts and content management systems tools require databases in order to store
dynamic data.
▪ It requires the scripting software to be installed on the server.
▪ The nature of dynamic scripts creates new security concerns, in some cases making it easier
for hackers to gain access to servers exploiting code flaws.
INTRODUCTION TO .NET

.NET Framework
.NET is an open source developer platform used for building many different type of application.
▪ It consist of developer tools, programming languages and libraries to build desktop, web
application, websites and web services and also games.
▪ It is designed and developed by Microsoft and the first version was released in the year
2002(.NET Framework 1.0).
▪ This framework provides various services like memory management, networking, security,
memory management, and type-safety

.Net Framework Architecture

Common Language Runtime (CLR)


It is the run-time environment in the .NET Framework that executes the code and helps in making the
development process easier by providing the various services.
It is a program execution engine that loads and executes the program. It converts the program into
native code. The Common Language Runtime (CLR) uses Just In Time (JIT) compiler to converts
Intermediate Language (MSIL) to Native code/ Machine code.
It acts as an interface between the framework and operating system. It does exception handling,
memory management, and garbage collection.
Suppose if we have written a C# or VB program and save it in a file which is known as the Source
code.
As CLR is common so it allows an instance of a class that written in a different language to call a
method of the class which written in another language.
The CLR Provides a Number of Services
That Include:
• Loading and execution of codes Language, platform, and architecture independence
• Memory management
• Security management
• Verification of type safety Providing meta data
• Managing exceptions and errors
Framework Class Library (FCL)

Framework Class Library (FCL) is a standard library that is a collection of thousands of classes are
used to build an application. The Framework Class Library or FCL provides the system functionality
in the .NET Framework as it has various classes, data types, interface.

Namespaces in the Framework Class Library are a group of related classes and interfaces that can be
used by all the .NET framework languages.
In other languages such as C, we use header files, in java we use package similarly we use "using
system" in .NET, where using is a keyword and system is a namespace.

Common Type System (CTS)


CTS deals with the data type. We know that each and ever language has its own data type and one
language data type cannot be understandable by languages but .NET Framework language can
understand all the data types CTS is responsible for understanding all the data type.

There are 2 Types of CTS


Value Types: Value Types will store the value directly into the memory location.
Reference Types: Reference Types will contain a memory address of value because reference types
won't store the variable value directly in memory.
Common Language Specification (CIS)
It defines a set of rules and restrictions that every language must follow which runs under the .NET
framework. The languages which follow these set of rules are said to be CIS Compliant. In simple
words, CIS enables cross-language integration or Interoperability.
CLS is responsible for converting the different .NET programming language syntactical rules and
regulations into CLR understandable format.
Microsoft Intermediate Language (MSIL) / Intermediate Language (IL)
• Microsoft Intermediate Language (MSIL) is a CPU-independent set of instructions that can be
efficiently converted to the native code.
• MSIL is machine independent and can be efficiently compiled into native code.
• The CLR has a just in time (JIT) compiler which converts the MSIL code into native machine code.
Thus, before executing on CPU, MSIL must be translated by a JIT compiler. There is a JIT compiler
for each machine architecture supported. The same MSIL will run on any supported machine.

Just-in-Time (JIT) Compiler

Just-In-Time Compiler(JlT) is a part of Common Language Runtime (CLR) in .NET which is responsible
for managing the execution of .NET programs regardless of any .NET programming language.
A language specific compiler converts the source code to the intermediate language (IL) or Microsoft
Intermediate Language (MSIL).
This intermediate language (IL) is then converted into the machine code by the Just-in-Time (JIT)
compiler.
There are three types of JIT compilation
Normal JIT Compilation With the Normal JIT Compiler methods are compiled when called at runtime
after execution this method is stored in the memory.
Econo JIT Compilation It compiles methods when called at runtime and removes them from memory
after execution.
Pre-JIT Compilation All the source code is compiled into the machine code at the same time in a single
compilation cycle using the Pre-JIT Compiler.

Features of .NET
1. Common Language Runtime
2. Common Type System
3. Language Interoperability
4. Multi Language Support
5. Security
6. Memory Management
7. Version Compatibility
8. Easy and Rich Debugging Support
9. Simplified Development
10. Framework Class Library

Visual studio Features:


1. Code Editing
2. Debugging
3. Intellisense
4. Project Template
5. Source control
6. Testing
7. Deployment
8. Cross Platform Development
9. Extension Marketplace
10. Integrated development environment
Introduction to C#

C# (C-Sharp) :
C# (C-Sharp) is object-oriented programming language created by Microsoft that runs on the .NET
Framework.
C# has roots from the C family, and the language is close to other popular languages like C++ and Java.

➢ C# is used for developing:

❖ Mobile applications

❖ Desktop applications

❖ Web applications

❖ Web services

❖ Games

❖ Database applications

Using Visual Studio.Net IDE for compiling and executing C# programs,


take the following steps −

➢ Start Visual Studio.

➢ On the menu bar, choose File -> New -> Project.

➢ Choose Visual C# from templates, and then choose Windows.

➢ Choose Console Application.

➢ Specify a name for your project and click OK button.

➢ This creates a new project in Solution Explorer.

➢ Write code in the Code Editor.

➢ Click the Run button or press F5 key to execute the project.


C# program structure: A C# program consists of the following parts:

➢ Namespace declaration

➢ A class

➢ Class methods

➢ Class attributes

➢ A Main method

➢ Statements and Expressions

➢ Comment

C# program Structure:

➢ C# Comments: Comments can be used to explain C# code, and to make it more readable. It can also
be used to prevent execution when testing alternative code.

❖ Single-line comments start with two forward slashes (//).

❖ Multi-line comments start with /* and ends with */. (will not be executed).

➢ C# Identifiers: Identifiers are descriptive names in order to create understandable and maintainable
code.
The general rules for naming Identifiers/variables are:

❖ Names can contain letters, digits and the underscore character (_)

❖ Names must begin with a letter

❖ Names should start with a lowercase letter and it cannot contain whitespace

❖ Names are case sensitive ("myVar" and "myvar" are different variables)

❖ Reserved words (like C# keywords, such as int or double) cannot be used as names

C# program Structure:

➢ C# Variables: Variables are containers for storing data values. All C# variables must be identified with
unique names.

❖ Syntax: type variableName = value;

❖ Example: string name = “K. Adisesha";


int x = 5, y = 6, z = 50;

➢ C# Constants: The const keyword is useful when you want a variable to always store the same value.
Example: const int Num = 15;
Num = 20; // error

➢ Display Variables: The WriteLine() method is often used to display variable values to the console
window. To combine both text and a variable, use the + character:
Example: string name = "John"; Console.WriteLine("Hello " + name);

Features of C#
Applications of C#
C# can be used in various applications supported by .NET
• Console applications • Cloud native apps and
services
• Windows libraries and components • Developing ASP.NET
projects
• Web applications • Web services and Web
API
• Developing Windows controls • Native iOS and Android
mobile apps
• Creating Web controls • Windows services

C# Language Fundamentals
C# Tokens: all the characters of a C# program are grouped into a symbol called token.
1. Identifiers – case sensitive names used by programmers to identify variables,
methods, classes and objects.
2. Keywords – it appears in lowercase and cannot be used as identifiers.
3. Operators – these are symbols that represent arithmetic, relational, assignment
and logical operations. They operate on operands and return result.
4. Punctuators – it is used to divide a program into segments ( , { } )
5. Literals – specific types of data explicitly entered into code.

You might also like