Getting Started with .NET
Learn More @ http://www.learnnowonline.com Copyright Š by Application Developers Training Company
Objectives • Learn the advantages and architecture of the .NET Framework • Examine sample Microsoft Intermediate Language code • Set up a development profile in Visual Studio .NET • Create Console Application projects in Visual Studio .NET • View the code that Visual Studio generates and understand what it does • Explore the Object Browser in the Integrated Development Environment • Take advantage of Visual Studio’s exception-handling features Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
Agenda • Thinking about .NET • Using Visual Studio 2010 • Debugging and Handling Exceptions
Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
What Is .NET, Anyway? • 1991: Windows "sits" on top of DOS Windows apps require Windows runtime environment Windows apps provide a consistent API for communicating with drivers, devices, and so on
• 2001: .NET Runtime "sits" on top of Windows .NET apps require .NET runtime environment .NET apps provide a consistent API for working with Windows, data structures, types, and more
• .NET provides an environment that handles data types, memory management, APIs, and much moreLearn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
What Is .NET, Anyway? • .NET Framework 2.0: Third version of the Objectoriented programming environment • .NET Framework 3.0: Developed to work with Windows Vista and Windows Server 2008 Can create command-line apps through rich client apps, including Web applications
• .NET is open Can program in many different languages Can use different tools o
Not limited to VB/C# and Visual Studio
.NET SDK is a free download o
No need to buy Visual Studio, but it's a lot more productive! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
Why .NET? • Before .NET, software development required mastery of multiple technologies and authoring tools Manually stitched together various programming tools
• For example: Web sites? Required VB Scripting or JScript and HTML Database apps? SQL/SQL Server Business applications? Visual Basic Office applications? VBA Streamlined graphics? C++ Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
Advantages of .NET • .NET provides remedies: Object-oriented view of Windows: .NET Framework encapsulates lots of functionality into classes Application security built in Deploying applications is easier o
Assembly contains and describes unit of deployment
Versioning issues largely handled without effort Assemblies can be digitally signed Unless using COM, no need for registration All .NET languages are interoperable Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
.NET Framework Architecture VB
C++
C#
JScript
…
ASP.NET
Windows Forms
ADO.NET and XML Base Class Library Common Language Runtime Windows
COM+ Services Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
Visual Studio .NET
Common Language Specification
Common Language Runtime • Common Language Runtime (CLR) provides runtime environment for all .NET applications • CLR's purpose is to load and run applications compiled to Intermediate Language (IL) Each .NET compiler creates IL as its output
• CLR manages .NET base services:
Memory management Garbage collection Exception handling Loading/Running applications Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
CLR and Running Code • CLR allows you to run both managed and unmanaged code Unmanaged code runs outside the CLR o
VB6/C++ code compiled without .NET
Managed code runs "within" the CLR, and benefits from the CLR's features
Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
CLR and Compilers • .NET Compilers create Microsoft Intermediate Language (MSIL, or just IL) as output • At execution time, Just-In-Time (JIT) compiler converts code to native executable
Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
More about JIT • JIT compiler takes native processor into account Creates code optimized for the local environment Makes decisions about how to optimize code at runtime
• Only needs to compile the application once: Compiled "bits" cached locally Performance overhead is very slight, if any
• Remember: .NET Runtime/CLR must be installed on client computers in order to run .NET code Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
.NET Framework Base Class Library • BCL consists of classes that provide base functionality for .NET Framework And many classes that make your life as a developer easier Library of classes used by all .NET applications
• Contains large number of classes (blocks of functionality, including properties, methods, and events) grouped into namespaces Each class within a namespace has a unique name
• BCL's namespaces group classes into common blocks of functionality Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
Some BCL Namespaces • • • • • • • • • •
System System.Data System.Diagnostics System.Globalization System.IO System.Text System.Text.RegularExpressions System.Web System.Windows.Forms System.Xml Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
.NET Languages • Microsoft provides several .NET languages: Visual Basic, Visual C#, C++, JScript Other vendors provide other languages o
Python, Fortran, Cobol, and many more
• How do languages interoperate? .NET provides: o
o
Common Language Specification (CLS): Describes how .NET languages should work Common Type System (CTS): Describes how data types should work together
In the end: All .NET languages compile to IL Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
Examining a .NET Application: Introducing Assemblies • Compile managed code: create assembly • Theoretically, assembly can contain multiple modules Visual Studio only supports creating single-module assemblies Output looks like EXE or DLL o
Actually contains compiled IL, and information about the assembly
Metadata contains a manifest that describes the assembly, procedures, and types that it exports, along with other required assemblies Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
What's in the Manifest? • Version, name, culture, security requirements • List of other files in assembly and cryptographic hash for each file • List of public types • List of external required references • Use ILDASM.EXE to examine contents
Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
What Can You Create? • .NET allows you to create a large range of applications • Visual Studio includes templates for (among others):
Windows application Console application Class library Windows control library Web control library Web application XML Web Service Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
Agenda • Thinking about .NET • Using Visual Studio 2010 • Debugging and Handling Exceptions
Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
Using Visual Studio 2010 • Creating applications using Notepad and command-line compilers is possible But it's not very efficient
• Visual Studio provides a huge number of timesaving tools, along with built-in compiler support • Supports Visual Basic, C#, and more
Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
Working with Profile Settings • User profiles allow you to control Visual Studio behavior • Can use pre-set defaults for:
Options Menus Key bindings Toolbars
• Pick a profile when you first run Visual Studio Or change it any time
• Demonstration saves and restores profile Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
Agenda • Thinking about .NET • Using Visual Studio 2010 • Debugging and Handling Exceptions
Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
Debugging and Handling Exceptions • No matter how carefully you code You'll make coding errors Errors will occur at runtime
• Three types of errors: Syntax errors Runtime errors Logic errors
• Visual Studio provides powerful tools to help in your debugging process Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
Learn More! • This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details!
Learn More @ http://www.learnnowonline.com Copyright Š by Application Developers Training Company