C# Programming Unit -1.

Slides:



Advertisements
Similar presentations
Introduction to .NET Framework
Advertisements

.NET Framework Overview
Using.NET Platform Note: Most of the material of these slides have been taken & extended from Nakov’s excellent overview for.NET framework, MSDN and wikipedia.
History of.Net Introduced by Microsoft Earlier technology was VC++ and VB VC++ comes with so many library and VB was so easy to use and not flexible to.
.NET Framework Overview Pingping Ma Nov 16 th, 2006.
.NET Technology.
Overview of the.NET Framework. What is the.NET Framework A new computing platform designed to simplify application development A consistent object-oriented.
Introducing the Common Language Runtime for.NET. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution.
Introducing the Common Language Runtime. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution engine.
Tahir Nawaz Visual Programming C# Week 2. What is C#? C# (pronounced "C sharp") is an object- oriented language that is used to build applications for.
Session-02. Objective In this session you will learn : What is Class Loader ? What is Byte Code Verifier? JIT & JAVA API Features of Java Java Environment.
Intro to dot Net Dr. John Abraham UTPA – Fall 09 CSCI 3327.
Lecture Roger Sutton CO530 Automation Tools 5: Class Libraries and Assemblies 1.
1 Introduction to.NET Framework. 2.NETFramework Internet COM+ Orchestration Orchestration Windows.NET Enterprise ServersBuildingBlockServices Visual Studio.NET.
Introduction to .Net Framework
ASP.NET The.NET Framework. The.NET Framework is Microsoft’s distributed run-time environment for creating, deploying, and using applications over the.
CSC300 Visual Programming Dr. Craig Reinhart. Objectives Teach the basics of C++ –You won’t be an expert but hopefully a very good novice –GUI development.
1 8/29/05CS360 Windows Programming Professor Shereen Khoja.
Session 1 - Introduction and Data Access Layer
 Internet providing backbone for applications  Use of several web sites and devices to provide one complete solution  Software as services  Quick software.
Understanding Code Compilation and Deployment Lesson 4.
Assemblies & Namespaces1. 2 Assemblies (1).NET applications are represented by an assembly An assembly is a collection of all software of which the application.
Introduction .NET Framework
C# Overview and Features. Content I.History of C# II.Architecture III.How to install IV.Features V.Code Sample VI.Microsoft.NET Platform VII.Why use C#
.NET Framework Danish Sami UG Lead.NetFoundry
MSIL & CLI Kun-Yuan Shieh.
tom perkins1 XML Web Services -.NET FRAMEWORK – Part 1 CHAPTER 1.1 – 1.3.
Intro to dot Net Dr. John Abraham UTPA CSCI 3327.
PRIOR TO WEB SERVICES THE OTHER TECHNOLOGIES ARE:.
.NET Ying Chen Junwei Chen. What is Microsoft.NET. NET is a development platform Incorporated into.NET COM+ component services ASP web development framework.
Microsoft .NET A platform that can be used for building and running windows and web applications such that the software is platform and device-independent.
Getting Started with.NET Getting Started with.NET/Lesson 1/Slide 1 of 31 Objectives In this lesson, you will learn to: *Identify the components of the.NET.
NAMESPACE. Namespaces Namespaces are a way to define the classes and other types of information into one hierarchical structure. System is the basic namespace.
Text Introduction to.NET Framework. CONFIDENTIAL Agenda .NET Training – Purpose  What is.NET?  Why.NET?  Advantages  Architecture  Components: CLR,
Intro to ASP.NET CS-422 Dick Steflik. What is.NET As applications in the Enterprise become more and more netcentric and less and less standalone.NET is.
Diploma of Website Development Getting Started With ASP.NET
C# Diline Giriş.
Computer System Structures
.NET Framework.
Introduction to Visual Basic. NET,. NET Framework and Visual Studio
Introducing the Microsoft® .NET Framework
What is .NET.
Introduction to .NET framework
Object Oriented Programming in
.NET Omid Darroudi.
Jim Fawcett CSE687 – Object Oriented Design Spring 2016
Done By: Ashlee Lizarraga Ricky Usher Jacinto Roches Eli Gomez
An Introduction to the Shared Source Common Language Infrastructure (SSCLI) Damien Watkins Copyright Watkins 2002.
Foundations of .Net Programming with C#
.Net A brief introduction to
Introduction to .NET Framework Ch2 – Deitel’s Book
Overview of C.
Application Foundation
Introduction Enosis Learning.
2.1. Compilers and Interpreters
1.1. .NET architectural components and .NET Core
.NET and .NET Core 2. .NET Runtimes Pan Wuming 2017.
Part C - Introduction to Programming and the .NET Framework
Introduction to C# AKEEL AHMED.
Introduction Enosis Learning.
Programming in C# CHAPTER 1
Advanced Programming: C# Lecture 01: Introduction
.NET Overview Yingcai Xiao.
Introduction to .NET By : Mr. V. D. Panchal Content :
Module 10: Implementing Managed Code in the Database
(Computer fundamental Lab)
Java Programming Introduction
.NET Base Type (CTS Data Type) Managed Extensions for C++ Keyword
NAMESPACE.
DOT NET ARCHITECTURE (OR) DOT NET FRAME WORK ARCHITECTURE
Presentation transcript:

C# Programming Unit -1

Objectives The CLR and .NET Framework: Understand the motivation behind the .NET platform, Common Language Infrastructure (CLI). Common Type System (CTS), Common Language Specification (CLS) Common Language Runtime (CLR), Assembly, metadata, namespace, type distinction, Contrast single-file and multi-file assemblies, Common Intermediate Language (CIL), Platform independent .NET(Mono / Portable .NET distributions).

What is .NET : A robust development and runtime environment. A platform for building fast web and desktop applications. Programming language agnostic. A set of specifications submitted to ECMA to allow ports to non-Windows operating systems. A runtime that provides memory management and type verification.

What is the .NET Framework? The .NET Framework is a new and revolutionary platform created by Microsoft for developing applications.   It is a platform for application developers. It is a Framework that supports Multiple Language and Cross language integration. It has IDE (Integrated Development Environment). Framework is a set of utilities or can say building blocks of your application system.

.NET Framework Contd… .NET is a platform independent but with help of Mono Compilation System (MCS). MCS is a middle level interface. .NET Framework provides interoperability between languages i.e. Common Type System (CTS) . .NET Framework also includes the .NET Common Language Runtime (CLR), which is responsible for maintaining the execution of all applications developed using the .NET library. The .NET Framework consists primarily of a gigantic library of code.

.Net framework Architecture Diagram

.NET components Common Type System (CTS): A standard that specifies how Type definitions and specific values of Types are represented in computer memory. It is intended to allow programs written in different programming languages to easily share information. Common Language Specification (CLS): A set of base rules to which any language targeting the CLI should conform in order to interoperate with other CLS-compliant languages. The CLS rules define a subset of the Common Type System.

.NET components Contd.. Common Language Runtime (CLR): A library of utility classes for building desktop, web, or any type of application, as well as a runtime for executing .NET code with garbage collection and type verification. Common Intermediate Language (CIL): All .NET languages compile to this platform-independent language. Assemblies: A new name and structure for EXE and DLL files.

Representation of CLS and CLR

Common Type System (CTS)

Common Type System -CTS The common type system defines how types are declared, used, and managed in the common language runtime, and is also an important part of the runtime's support for cross-language integration. The common type system performs the following functions: Establishes a framework that helps to enable cross-language integration, type safety, and high-performance code execution.

Common Type System -CTS Defines rules that languages must follow, which helps ensure that objects written in different languages can interact with each other. Provides a library that contains the primitive data types (such as Boolean, Byte, Char, Int32, and UInt64) used in application development. 4. Provides an object-oriented model that supports the complete implementation of many programming languages.

What type of applications can I develop? ASP.NET Web applications Windows Form based applications Console applications Component Libraries Windows Custom Controls Windows Services Web Custom Controls Web services

Features of .NET Rich Functionality out of the box Easy development of web applications OOPs Support Multi-Language Support Multi-Device Support Automatic memory management Compatibility with COM and COM+ Strong XML support Ease of deployment and configuration Security

Release History Version Version Number Release Date Visual Studio Default in Windows 1.0 1.0.3705.0 2002-02-13 Visual Studio .NET Windows XP Tablet and Media Center Editions[4] 1.1 1.1.4322.573 2003-04-24 Visual Studio .NET 2003 Windows Server 2003 2.0 2.0.50727.42 2005-11-07 Visual Studio 2005 Windows Server 2003 R2 3.0 3.0.4506.30 2006-11-06 Windows Vista, Windows Server 2008 3.5 3.5.21022.8 2007-11-19 Visual Studio 2008 Windows 7, Windows Server 2008 R2 4.0 4.0.30319.1 2010-04-12 Visual Studio 2010

.NET Framework version history Windows Presentation Foundation (or WPF) Windows Communication Foundation (or WCF) Language Integrated Query (or LINQ)

Class Library The Base Class Library (BCL) includes a small subset of the entire class library and is the core set of classes that serve as the basic API of the Common Language Runtime. The classes in mscorlib.dll and some of the classes in System.dll and System.core.dll are considered to be a part of the BCL. The BCL classes are available in both .NET Framework as well as its alternative implementations including .NET Compact Framework, Microsoft Silverlight and Mono.

Base Class Libraries

Common Language Runtime The Common Language Runtime (CLR) is an Execution Environment . The main function of Common Language Runtime (CLR) is to convert the Managed Code into native code and then execute the Program. It works as a layer between Operating Systems and the applications written in .Net languages that conforms to the Common Language Specification (CLS). The Common Language Runtime (CLR) 's Just In Time (JIT) compilation converts Intermediate Language (MSIL) to native code on demand at application run time.

CLR- Execution Model Execution Model Let’s imagine you’ve built a managed component for the Intel Pentium III platform. It works fine. Later in the year, Intel release a super new chip. When Microsoft releases a new version of the JIT, it’s possible that this new version of the JIT will have learned a few new tricks, e.g., to make use of the new improved instruction set of the new Intel chip or new CPU registers! And finally, Microsoft plans to offer a tool called Ngen.exe. This tool will compile your assemblies into native code and save the resultant binary executable code to disk (the Global Assembly Cache). When the assemblies are next loaded, the binary code is already available, thus improving start-up time and execution speeds. SLIDE TRANSISTION: Demo on the Common Language Runtime ADDITIONAL INFORMATION FOR PRESENTER:

Compilation And Execution Assembly Code (IL) Source Code Language Compiler Metadata Execution JIT Compiler Native Code The diagram above illustrates the process used to compile and execute managed code, that is, code that uses the CLR. Source code written in C#, VB.NET, or some other language that targets the CLR is first transformed into MSIL by the appropriate language compiler. Before execution, this MSIL is JIT compiled into native code for whatever processor the code will run on. The default is to JIT compile each method when it is first called, but it’s also possible to “pre-JIT” the MSIL. With this option, all methods are compiled before the application is loaded, so the overhead of JIT compilation on each initial method call is avoided. One point worth noting is that all languages targeting the CLR should exhibit roughly the same performance. While some compilers may produce better MSIL code than others, large variations in execution speed are unlikely. At installation or the first time each method is called

CLR

Components of CLR Class Loader: This loads classes into the runtime. MSIL to native code compiler: This converts MSIL code into native code. Code manager: This manage the code during execution i.e provides code check, the resources it needs during execution. Garbage Collector: provide automatic memory management and avoid memory leaks. Security Engine: This enforces security restrictions and CAS. Type Checker: This enforces strict type checking. Thread Support: This provides multithreading support to applications. Exception Manager : This provides a mechanism to handle the run-time exceptions. Debug Engine : Allow you to debug different type of applications. COM marshaler : This allows .net application to exchange data with COM applications. BASE Class library : This provides the types the applications needed at runtime.

Base Class Library Support The CLR Architecture Class Loader MSIL to Native Compilers (JIT) Code Manager Garbage Collector (GC) Security Engine Debug Engine Type Checker Exception Manager Thread Support COM Marshaler Base Class Library Support

An Assembly is a logical unit of code What is an assembly? An Assembly is a  logical unit of code Assembly physically exist as DLLs or EXEs One assembly can contain one or more files The constituent files can include any file types like image files, text files etc. along with DLLs or EXEs When you compile your source code by default the exe/dll generated is actually an assembly Unless your code is bundled as assembly it can not be used in any other application When you talk about version of a component you are actually talking about version of the assembly to which the component belongs. Every assembly file contains information about itself. This information is called as Assembly Manifest.

Functions or Features: It contains the code that a CLR executes. MSIL code in a portable executable file will not be executed if it doesn't contain the associated assembly manifest. Each assembly can have only one entry point( that is DllMain, WinMain, Main ) It forms a security boundary. An assembly is a unit at which permissions are requested and granted. Type Boundary: Every type identity includes the name of the assembly in which its resides.

Features Contd.. Reference Scope Boundary: The assembly manifest contains assembly metadata that is used for resolving types and satisfying resources requests. Version Boundary: The assembly is the smallest versionable unit in the CLR, all types and resources in the same assembly are versioned as a unit. It forms a deployment unit: When an application starts, only the assemblies that the application initially calls must be present. Other assemblies, such as localization resources or assemblies containing utility classes can be retrieved on demand.

Types of Assembly There are three types of assembly. Private Assembly Shared Assembly Satellite Assembly

Types of Assembly Private Assembly:- These are those assemblies, which are used by single application and are stored in the application directory or a sub-directory beneath. Here the scope of this assembly is limited to the application itself and this assembly can't be shared by multiple assemblies. If you want to use this private assembly, you have to either copy this assembly or paste under the bin folder or you can create the reference of this assembly using the Add reference dialog box and use this assembly. The limitation with the private assembly is that it can't be accessed by two application.

Types of Assembly Contd… 2. Shared Assembly:- A shared assembly can be used by multiple assemblies. A shared assembly is normally stored in GAC (Global Assembly Cache), which is a repository of assemblies maintained by the .Net runtime. Shared assemblies are usually libraries of code which many applications will find useful e.g. crystal report classes which will be used by all application for reports.

Types of Assembly Contd… Satellite Assembly:- In multi lingual application in .Net to support multilingual functionality you can have modules which are customized for locations. These assemblies are called as satellite assemblies. Here in these assemblies we can distribute these assemblies separately than the core modules.

Namespace A collection of related set of classes, structures, enumerators etc. It is similar to package in Java. All C# applications are developed using classes from the .NET System namespace. The namespace with all the built-in C# functionality is the System namespace.

Some Important Namespaces System: Includes essential classes and base classes for commonly used data types, events, exceptions and so on System.Collections: Includes classes and interfaces that define various collection of objects such as list, queues, hash tables, arrays, etc System.Data: Includes classes which lets us handle data from data sources System.Data.OleDb: Includes classes that support the OLEDB .NET provider System.Data.SqlClient: Includes classes that support the SQL Server .NET provider System.Diagnostics: Includes classes that allow to debug our application and to step through our code System.Drawing: Provides access to drawing methods

Namespaces Contd… System.Globalization: Includes classes that specify culture-related information System.IO: Includes classes for data access with Files System.Net: Provides interface to protocols used on the internet System.Reflection: Includes classes and interfaces that return information about types, methods and fields System.Security: Includes classes to support the structure of common language runtime security system System.Threading: Includes classes and interfaces to support multithreaded applications System.Web: Includes classes and interfaces that support browser-server communication System.Web.Services: Includes classes that let us build and use Web Services System.Windows.Forms: Includes classes for creating Windows based forms System.XML: Includes classes for XML support

Role of the Common Language Infrastructure (CLI) When C# and the .NET platform were released to the world at large, Microsoft Corporation submitted two formal specifications to ECMA (European Computer Manufacturers Association). Once approved, these same specifications were submitted to the International Standards Organization (ISO) and ratified shortly thereafter. The two specifications are: ECMA-334, which defines the syntax and semantics of the C# programming language. ECMA-335, which defines numerous details of the .NET platform, collectively termed the Common Language Infrastructure (CLI).

Common Language Infrastructure CLI allows for cross-language development. Four components: Common Type System (CTS) Meta-data in a language agnostic fashion. Common Language Specification – behaviors that all languages need to follow. A Virtual Execution System (VES).

Common Language Infrastructure The purpose of the Common Language Infrastructure is to provide a language-neutral platform for application development and execution, including functions for Exception handling, Garbage Collection, security, and interoperability. By implementing the core aspects of the .NET Framework within the scope of the CLI, this functionality will not be tied to a single language but will be available across the many languages supported by the framework. Microsoft's implementation of the CLI is called the Common Language Runtime, or CLR.

Common Language Infrastructure The CLI specification describes the following four aspects The Common Type System (CTS)  A set of data types and operations that are shared by all CTS-compliant programming languages. Metadata : Information about program structure is language-agnostic, so that it can be referenced between languages and tools, making it easy to work with code written in a language you are not using.

Common Language Infrastructure Common Language Specification (CLS)  A set of base rules to which any language targeting the CLI should conform in order to interoperate with other CLS-compliant languages. The CLS rules define a subset of the Common Type System. Virtual Execution System (VES)  The VES loads and executes CLI-compatible programs, using the metadata to combine separately generated pieces of code at runtime.

CLR versus CLI. CLR is actually an implementation by Microsoft of the CLI (Common Language Infrastructure) . CLI is an open specification. CLR is really a platform specific implementation.

Role of CIL .NET language compilers do not emit native platform code.  Rather, they emit platform-independent instructions called the Common Intermediate Language (CIL).   Unlike Java bytecode, CIL is not interpreted. It is just-in-time compiled (JITed) at runtime.  You may see CIL referred to by a few other names: IL or MSIL.

What is Mono/ Platform independent Mono is a software platform designed to allow developers to easily create cross platform applications. It is an open source implementation of Microsoft's .Net Framework based on the ECMA standards for C# and the Common Language Runtime.

MONO Mono can be run on Android, BSD, iOS, Linux, Mac OS X, Windows, Solaris, and Unix operating systems as well as some game console operating systems such as the ones for the PlayStation 3, Wii , and Xbox 360. Mono is a free and open source project led by Xamarin (formerly by Novell and originally by Ximian) to create an Ecma standard compliant .NET-compatible set of tools including, among others, a C# compiler and a Common Language Runtime.

The Components There are several components that make up Mono: C# Compiler - Mono's C# compiler is feature complete for C# 1.0, 2.0, 3.0, and 4.0 (ECMA). Mono Runtime - The runtime implements the ECMA Common Language Infrastructure (CLI). The runtime provides a Just-in-Time (JIT) compiler, an Ahead-of-Time compiler (AOT), a library loader, the garbage collector, a threading system and interoperability functionality. Base Class Library - The Mono platform provides a comprehensive set of classes that provide a solid foundation to build applications on. These classes are compatible with Microsoft's .Net Framework classes. Mono Class Library - Mono also provides many classes that go above and beyond the Base Class Library provided by Microsoft. These provide additional functionality that are useful, especially in building Linux applications. Some examples are classes for Gtk+, Zip files, LDAP, OpenGL, Cairo, POSIX, etc.

Mono Environment for Linux

Mono for MAC

Mono Open Source for all

Mono for Android

The Benefits There are many benefits to choosing Mono for application development: Popularity - Built on the success of .Net, there are millions of developers that have experience building applications in C#. There are also tens of thousands of books, websites, tutorials, and example source code to help with any imaginable problem. Higher-Level Programming - All Mono languages benefit from many features of the runtime, like automatic memory management, reflection, generics, and threading. These features allow you to concentrate on writing your application instead of writing system infrastructure code. Base Class Library - Having a comprehensive class library provides thousands of built in classes to increase productivity. Need socket code or a hashtable? There's no need to write your own as it's built into the platform.

The Benefits Cross Platform - Mono is built to be cross platform. Mono runs on Linux, Microsoft Windows, Mac OS X, BSD, and Sun Solaris, Nintendo Wii, Sony PlayStation 3, Apple iPhone. It also runs on x86, x86-64, IA64, PowerPC, SPARC (32), ARM, Alpha, s390, s390x (32 and 64 bits) and more. Developing your application with Mono allows you to run on nearly any computer in existence. Common Language Runtime (CLR) - The CLR allows you to choose the programming language you like best to work with, and it can interoperate with code written in any other CLR language. For example, you can write a class in C#, inherit from it in VB.Net, and use it in Eiffel. You can choose to write code in Mono in a variety of programming languages.

Short Questions What is Common Language Infrastructure (CLI) .Explain the role of it? What is Common Type System (CTS) explain with points? What is Common Language Specification (CLS) give some points? Write some difference point between class library and console application projects? What is managed and unmanaged code with diagram? What is namespace ? Explain the use of any five namespaces? What is JIT compiler and write the types of it ?

Short Questions What is the role of Common Type System (CTS) ? What is Common Language Specification (CLS) Explain ? Write short notes on the following: Assembly metadata namespace type distinction What is managed and unmanaged code? What is JIT compiler and explain the types of it?

Long Questions What is .NET frame work. Explain the architecture of it ? Explain the working of Common Language Runtime? What are the features of .NET framework ? What is assembly, explain the type of assembly in detail? What is Mono project explain the Portable .NET distributions of it ? What is common language specification explain in detail?

References Books: Web: The Complete Reference C# 4.0 ,Tata Mc Graw –Hill Edition, Herbert Schildt [Herbert Schildt] C# 2010 for Programmers, Pearson Education, Paul J. Deitel, Harvey M. Deitel [Paul] Web: http://download.microsoft.com/download/8/e/7/8e725d96-7ec3-498b-9fa7-86779aed101f/dotnet%20tutorial%20for%20beginners.pdf http://www.visualbuilder.com/dotnet/tutorial http://www.c-sharpcorner.com/