Documente Academic
Documente Profesional
Documente Cultură
Net Framework
Contents
.Net Overview. .Net Platform .Net Framework Design Goals. .Net Framework
.Net Overview
It provides a mew programming interface to windows services and APIs & integrates number of technologies that emerged from Microsoft technologies from 90s. The .Net platform consists of 5 separate products groups: (A) development tools & libraries.(Set of languages) (B) web services.(Commercial web services) (C) specialized servers.(.Net enabled servers) (D) devices.(.Net enabled, non-pc devices) (E) Based on Object Oriented Programming.
.Net Framework
Web Services Web Forms
Windows Forms
Windows Platform
3.5 4.0
3.5.21022.8 4.0.30319.1
2007-11-19 2010-04-12
The Common Language Runtime (CLR) is the platform (or execution engine) on which managed code runs. The CLR shares much in common with a traditional operating system, and as such is a useful piece of the .NET Framework to be familiar with if you will be writing managed code. Managed Code is the term applied to any software running on the .NET Framework.
Common Language Runtime is the underpinning of the .NET Framework. CLR takes care of code management at program execution and provides various beneficial services such as memory management, thread management, security management, code verification, compilation, and other system services. The managed code that targets CLR benefits from useful features such as cross-language integration, cross-language exception handling, versioning, enhanced security, deployment support, and debugging.
Common Type System (CTS) describes how types are declared, used and managed in the runtime and facilitates cross-language integration, type safety, and high performance code execution. The Common Language Specification (CLS) is an agreement among language designers and class library designers to use a common subset of basic language features that all languages have to follow.
Highlights Common type system Mapping of data types. Programming language Framework Just-in-time (JIT) compilers JIT compiles intermediary language (MSIL) into native code Highly optimized for platform or device Garbage collector Permission and policy-based security Exceptions Threading Diagnostics and profiling
Purpose Of CLR
The CLR is the execution engine for this platform, and these are its requirements. Safe binary execution:- software to run software-components that originated across the network or Internet. Performance:- Internet development solutions opt for safety and flexibility, software to execute in the native machine language of the host system. Bug reduction :- software that targets the internet must be robust (If a client application crashes, it affects a single user. If a server application crashes it can affect thousands of users and cost a millions of dollars. ) Ease of integration :- software that targets the Internet must be able to integrate with all kinds of other software. This includes software that runs locally, software that runs remotely, and software written for a wide variety of platforms.
Namespaces and Classes Hierarchical, unified class libraries Unified and extensible provide system and base functionality and services Object-oriented: everything is an object! The systems uses the same classes offered to you Interfaces The .NET (Service) contracts Types Byte, Sbyte, Single, Double, String, Int16, etc. These all map to the common type system
Managed code is a big piece of the .NET Framework. Managed code is what your C# or VB.NET code becomes once you compile it. The reason managed code is so important is that through code management it is possible for your software to run in vastly different environments safely, securely, and efficiently.
Intermediate Language
IL is a binary assembly language that is compiled at runtime down to whatever machine language is appropriate for the host CPU. JIT compilation always happens with managed code, so managed code always executes in native machine language.
Code Management
Memory management :-The CLR maintains a managed heap that is used for all memory allocations. The CLR also cleans up objects that are no longer used. Security:- The CLR makes sure that code can not undermine a system if it is not trusted. Thread management :- Although you can create your own thread objects with managed code, the CLR maintains a thread pool which can be used by your software. Type safety :- At runtime the CLR checks all typecasting operations to be sure that the cast is valid. Code verification :- The CLR also asserts that all methods must have a return instruction. It is impossible for one instruction to runover into the next. Code verification is another feature that makes code robust, and makes it safe to run un-trusted or semi-trusted components.
Basic Introduction to C#
Why C# ?
Power of C with ease of Microsoft Visual Basic Minimal learning curve for everybody Much cleaner than C++ More structured than Visual Basic More powerful than Java
In OOP a component is: A reusable program that can be combined with other components in the same system to form an application. Example: a single button in a graphical user interface, a small interest calculator They can be deployed on different servers and communicate with each other
C# Overview
no global scope using System; namespace ConsoleTest { class Class1 { static void Main(string[] args) { } } }
Complete C# program:
C# Program Structure
Namespaces
Contain types and other namespaces Classes, structs, interfaces, enums, and delegates Constants, fields, methods, properties, indexers, events, operators, constructors, destructors No header files, code written in-line No declaration order dependence
Type declarations
Members
Organization
Simple Types
Integer Types
byte, sbyte (8bit), short, ushort (16bit) int, uint (32bit), long, ulong (64bit)
Character Types
Boolean Type
Arrays
Zero based, type bound Built on .NET System.Array class Declared with type and shape, but no bounds
int [ ] SingleDim; int [ , ] TwoDim; int [ ][ ] Jagged; SingleDim = new int[20]; TwoDim = new int[,]{{1,2,3},{4,5,6}}; Jagged = new int[1][ ]; Jagged[0] = new int[ ]{1,2,3};
Case sensitive (myVar != MyVar) Statement delimiter is semicolon Block delimiter is curly brackets Single line comment is Block comment is
; { } // /* */
Data
C# does not automatically initialize local variables (but will warn you)!
int (numbers) long (really big numbers) bool (true or false) char (unicode characters) float (7-digit floating point numbers) string (multiple characters together)
Data Manipulation
= assignment + addition subtraction * multiplication / division % modulus ++ increment by one -decrement by one
strings
Backslash is an escape:
Newline: \n Tab: \t
string/int conversions
string to numbers:
Numbers to strings:
string msg = Your number is + 123; string msg = It costs + string.Format({0:C}, 1.23);
String Example
using System; namespace ConsoleTest { class Class1 { static void Main(string[ ] args) { int myInt; string myStr = "2"; bool myCondition = true; Console.WriteLine("Before: myStr = " + myStr); myInt = int.Parse(myStr); myInt++; myStr = String.Format("{0}", myInt); Console.WriteLine("After: myStr = " + myStr); while(myCondition) ; } } }
Arrays
(page 21 of quickstart handout) Derived from System.Array Use square brackets [] Zero-based Static size Initialization:
int [ ] nums; int [ ] nums = new int[3]; // 3 items int [ ] nums = new int[ ] {10, 20, 30};
Arrays Continued
nums.Length
Arrays Final
Multidimensional
// 3 rows, 2 columns int [ , ] myMultiIntArray = new int[3,2] for(int r=0; r<3; r++) { myMultiIntArray[r][0] = 0; myMultiIntArray[r][1] = 0; }
Conditional Operators
== equals != not equals < less than <= less than or equal > greater than >= greater than or equal && || and or
Loops
for (initialize-statement; condition; increment-statement); { statements; }
while (condition) { statements; } Note: can include break and continue statements
member data member methods Class clsName { modifier dataType varName; modifier returnType methodName (params) { statements; return returnVal; } }
Class Constructors
Hello World
namespace Sample { using System; public class HelloWorld { public HelloWorld() { }
Construct or
Another Example
using System; namespace ConsoleTest { public class Class1 { public string FirstName = "Kay"; public string LastName = "Connelly"; public string GetWholeName() { return FirstName + " " + LastName; } static void Main(string[] args) { Class1 myClassInstance = new Class1(); Console.WriteLine("Name: " + myClassInstance.GetWholeName()); while(true) ; } } }
Contained in its own namespace References other namespaces with "using" Declares a publicly accessible application class Entry point is "static int Main( ... )" Writes "Hello World!" to the system console
Summary
C# builds on the .NET Framework component model New language with familiar structure
Easy to adopt for developers of C, C++, Java, and Visual Basic applications
Easily combined and ready to be used in WebPages. Powerful Fast Most of the works are done without getting stuck in low level programming and driver fixing and
ASP.NET provides a programming model and infrastructure that offers the needed services for programmers to develop Web-based applications. ASP.NET is a part of the .NET Framework, the programmers can make use of the managed Common Language Runtime (CLR) environment, type safety, and inheritance etc to create Web-based applications. You can develop your ASP.NET Web-based applications in any .NET complaint languages such as Microsoft Visual Basic, Visual C#, and JScript.NET. Developers can effortlessly access the advantage of these technologies, which consist of a managed Common Language Runtime environment, type safety, inheritance, and so on. With the aid of Microsoft VisualStudio.NET Web development becomes easier.
ASP.NET is Part of the .NET Framework The .NET Framework comprises over 3,400 classes that we can employ in our ASP.NET applications. We can use the classes in the .NET Framework to develop any type of applications. ASP.NET Pages are compiled When an ASP.NET page is first requested, it is compiled and cached on the server. This means that an ASP.NET page performs very rapidly. All ASP.NET code is compiled rather than interpreted, which permits early binding, strong typing, and just-in-time (JIT) compiling to native code. XML-Based ASP.NET configuration settings are stored in XML-based files, which are human readable and writable. Each one of our applications can have a different configuration file and we can extend the configuration scheme according to our necessities. Code-Behind logic The main problem with ASP Classic pages is that an *.asp page does not yield modularized code. Both HTML and Script are present in a single page. But Microsoft's ASP.NET implementation contains a new-fangled method to break up business logic code from presentation code. ASP.NET Pages are built with Server Controls We can easily build complex Web pages by bring together the pages out of ASP.NET server controls. For example, by adding validation controls to a page, we can easily validate form data.
Developers can build their works in these forms (a) Web Forms. (b) Web Services.
Web Forms
Web Forms permits us to build powerful forms-based Web pages. When building these pages, we can use Web Forms controls to create common UI elements and program them for common tasks. These controls permit us to rapidly build up a Web Form.
Web Services
Web services enable the exchange of data in client-server or server-server scenarios, using standards like HTTP, SOAP (Simple Object Access Protocol) and XML messaging to move data across firewalls. XML provides meaning to data, and SOAP is the protocol that allows web services to communicate easily with one another. Web services are not tied to a particular component technology or object-calling convention. As a result, programs written in any language, using any component model, and running on any operating system can access Web services.
Compiled applications no more server script Multi-language support vb, c#, Language enhancements OOP, Event-driven controls respond to client events on the server. Code and content separation Configuration enhancements Easier deployment Debugging improvements Benefits of the CLR Benefits of the .NET Framework library Multi-Processor support Consistent object model Integrated dev environment with VS.NET
User of type IPrincipal and contains user and security information (IsInRole & Name) Cache for accessing the ASP.NET caching infrastructure programmatically
Directives <% @ directive attribute=value %> @Page for web pages @Control for user controls @Reference for registering a control on a page @OutputCache for setting page caching options (Page) or fragment caching options (Control) Not case-sensitive
Controls
Web Server Controls Automatic Browser Customization Datagrid, textbox, dropdown Validation Controls HTML Server Controls (using runat=Server) Custom Controls User Controls Composite Custom Controls Rendered Controls 3rd Party see http://asp.net
Configuration
A look at the Web.config File <appSettings> - used for your own settings (connection strings,) <authentication> - how you determine who the user is <authorization> - what the user has access to <customErrors> - to redirect users to nice error pages <trace> - to control tracing in the application Custom configuration sections Elements & attributes are case-sensitive
Session State
Modes: InProc similar to old ASP StateServer a windows service SqlServer state stored in SQL Server Off Cookieless uses a URL identifier
Projects are compiled Note: changes to aspx pages may not require recompilation Compared to ASP script interpretation At Runtime (after youve built your project file): Step 1: the aspx page is compiled to a temporary dll and cached, if not already Step 2: the page is run Building in Debug vs. Release (pdb files / performance)
Design Time System.Web.UI.Page Inherits from WebForm1.cs/.vb Compiles Into MyProject.dll WebForm1 class
HTML
Thank You