Download presentation
Presentation is loading. Please wait.
1
Introduction to .NET Framework
Visual Programming Comp-315 Chapter #1 Introduction to .NET Framework & Introduction to C#
2
What Is .NET .NET is a new framework for developing web-based and windows-based applications within the Microsoft environment. The framework offers a fundamental shift in Microsoft strategy: it moves application development from client-centric to server-centric.
3
Framework, Languages, And Tools
VB.NET C# C++ Jscript … Common Language Specification ASP.Net Windows Forms Visual Studio .NET ADO.Net and XML Base Class Library Common Language Runtime (CLR)
4
Common Language Runtime (CLR)
CLR works like a virtual machine in executing all languages. All .NET languages must obey the rules and standards imposed by CLR. Examples: Object declaration, creation and use Data types,language libraries Error and exception handling Interactive Development Environment (IDE)
5
Common Language Runtime
Development Mixed language applications Common Language Specification (CLS) Common Type System (CTS) Standard class framework Automatic memory management Consistent error handling and safer execution Potentially multi-platform Deployment Removal of registration dependency Safety – fewer versioning problems
6
Common Language Runtime Multiple Language Support
CTS is a rich type system built into the CLR Implements various types (int, double, etc) And operations on those types CLS is a set of specifications that language and library designers need to follow This will ensure interoperability between languages
7
Compilation in .NET Code in VB.NET Code in C# Code in another
.NET Language VB.NET compiler C# compiler Appropriate Compiler IL(Intermediate Language) code CLR just-in-time execution
8
Intermediate Language (IL)
.NET languages are not compiled to machine code. They are compiled to an Intermediate Language (IL). CLR accepts the IL code and recompiles it to machine code. The recompilation is just-in-time (JIT) meaning it is done as soon as a function or subroutine is called. The JIT code stays in memory for subsequent calls. In cases where there is not enough memory it is discarded thus making JIT process interpretive.
9
Languages Languages provided by MS Third-parties are building
VB, C++, C#, J#, JScript Third-parties are building APL, COBOL, Pascal, Eiffel, Haskell, ML, Oberon, Perl, Python, Scheme, Smalltalk…
10
ASP.NET ASP.NET,the platform services that allow to program Web Applications and Web Services in any .NET language ASP.NET Uses .NET languages to generate HTML pages. HTML page is targeted to the capabilities of the requesting Browser ASP.NET “Program” is compiled into a .NET class and cached the first time it is called. All subsequent calls use the cached version.
11
C# Programming Language
Developed at Microsoft by Anders Hejlsberg et al Event driven, object oriented, visual programming language Based from C, C++ and Java Incorporated into .NET platform Web based applications can be distributed Programs that can be accessed by anyone through any device Allows communicating with different computer languages Integrated Design Environment (IDE) Makes programming and debugging fast and easy Rapid Application Development (RAD)
12
C# Translation and Execution
The C# compiler translates C# source code (.cs files) into a special representation called Microsoft Intermediate Language (MSIL) MSIL is not the machine language for any traditional CPU, but a virtual machine The Common Language Runtime (CLR) then interprets the MSIL file It uses a just-in-time compiler to translate from MSIL format to machine code on the fly
13
C# Compilation and Execution
C# source code MSIL C# compiler Machine code Just in time compiler
14
A Simple C# Program using System; class HelloWorld {
//========================================================== // // File: HelloWorld.cs // Classes: HelloWorld // // This program prints a string called "Hello, World!” using System; class HelloWorld { static void Main(string[] args) Console.WriteLine(“Hello, World!”); }
15
C# Program Structure Program specifications (optional)
//========================================================== // // File: HelloWorld.cs // Classes: HelloWorld // // This program prints a string called "Hello, World!” Library imports (optional) using System; Class and namespace definitions class HelloWorld { static void Main(string[] args) Console.WriteLine(“Hello, World!”); }
16
White Space and Comments
Includes spaces, newline characters, tabs, blanklines C# programs should be formatted to enhance readability, using consistent indentation! Comments Comments are ignored by the compiler: used only for human readers (i.e., inline documentation) Two types of comments Single-line comments use //… // this comment runs to the end of the line Multi-lines comments use /* … */ /* this comment runs to the terminating symbol, even across line breaks */
17
Identifiers Identifiers are the words that a programmer uses in a program An identifier can be made up of letters, digits, and the underscore character They cannot begin with a digit C# is case sensitive, therefore args and Args are different identifiers Sometimes we choose identifiers ourselves when writing a program (such as HelloWorld) Sometimes we are using another programmer's code, so we use the identifiers that they chose (such as WriteLine) using System; class HelloWorld { static void Main(string[] args) Console.WriteLine(“Hello World!”); }
18
Identifiers: Keywords
Often we use special identifiers called keywords that already have a predefined meaning in the language Example: class A keyword cannot be used in any other way All C# keywords are lowercase!
19
Namespaces Partition the name space to avoid name conflict!
All .NET library code are organized using namespaces! By default, C# code is contained in the global namespace To refer to code within a namespace, must use qualified name (as in System.Console) or import explicitly (as in using System; ) using System; class HelloWorld { static void Main(string[] args) Console.WriteLine(“Hello World!”); } class HelloWorld { static void Main(string[] args) System.Console.WriteLine(“Hello World!”); }
20
C# Classes Class bodies start with a left brace ({)
Each class name is an identifier Can contain letters, digits, and underscores (_) Cannot start with digits Can start with the at symbol Convention: Class names are capitalized, with each additional English word capitalized as well (e.g., MyFirstProgram ) Class bodies start with a left brace ({) Class bodies end with a right brace (})
21
C# Program Structure: Method
// comments about the class class HelloWorld { } static void Main (string[] args) { } // comments about the method Console.Write(“Hello World!”); Console.WriteLine(“This is from COMP-315!”);
22
C# Method and Statements
Methods Building blocks of a program The Main method Each console or windows application must have exactly one (actually can have more, but it is unlikely that you will see or use) All programs start by executing the Main method Braces are used to start ({) and end (}) a method Statements Every statement must end in a semicolon ;
23
Syntax and Semantics The syntax rules of a language define how we can put symbols, reserved words, and identifiers together to make a valid program The semantics of a program statement define what that statement means (its purpose or role in a program) A program that is syntactically correct is not necessarily logically (semantically) correct A program will always do what we tell it to do, not what we meant to tell it to do
24
Errors A program can have three types of errors
The compiler will find problems with syntax and other basic issues (compile-time errors) If compile-time errors exist, an executable version of the program is not created A problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally (run-time errors) A program may run, but produce incorrect results (logical errors)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.