This document provides an overview of the .NET framework and C# programming language. It discusses the .NET framework architecture including the common language runtime and base class library. It also covers advantages of the .NET platform like cross-language integration and security features. The document then presents an introduction to C# focusing on its design goals like interoperability. It demonstrates a simple "Hello World" program and describes key C# language features like namespaces, classes and predefined types. Finally, it provides an overview of the e-Sampark project which aims to provide citizens a single-window access to government services.
4. What is .Net?What is .Net?
New programming methodology
◦ Multiple Languages (VB.Net, C#, J#, Cobol.Net, etc.)
◦ JIT Compiler(just-in-time)
Primary Parts:
.Net Framework
Common Language Runtime (CLR)
RTM:
◦ 2002 (v1.0)
◦ 2003 (v1.1)
◦ 2005 (v2.0)
5. .Net Framework.Net Framework
Supports Web Standards
◦ HTML
◦ XML
◦ XSLT
◦ SOAP
◦ WSDL (Web Services)
ADO.Net: ActiveX Data Objects
ASP.Net: Active Server Pages
ILDASM: A tool used to properly display IL in a human
readable format.
.Net Compact Framework (mobile devices)
6. The .NET FrameworkThe .NET Framework
Common Language RuntimeCommon Language Runtime
Base Class LibraryBase Class Library
Common Language SpecificationCommon Language Specification
Common Language RuntimeCommon Language Runtime
ADO.NET: Data and XMLADO.NET: Data and XML
VBVB C++C++ C#C#
VisualStudio.NETVisualStudio.NET
ASP.NET: Web ServicesASP.NET: Web Services
and Web Formsand Web Forms
JScriptJScript ……
WindowsWindows
FormsForms
7. .NET Framework and CLR.NET Framework and CLR
CLR Execution ModelCLR Execution Model
VBVBSourceSource
codecode
CompilerCompiler
C++C++C#C#
CompilerCompilerCompilerCompiler
AssemblyAssembly
IL CodeIL Code
AssemblyAssembly
IL CodeIL Code
AssemblyAssembly
IL CodeIL Code
Operating System ServicesOperating System Services
Common Language RuntimeCommon Language Runtime
JIT CompilerJIT Compiler
Native CodeNative Code
ManagedManaged
codecode
UnmanagedUnmanaged
ComponentComponent
8. Advantages of .NetAdvantages of .Net
Write once, run everywhere
Multiple programming languages (20+)
Coding Reduction
◦ Controls
◦ Template projects
◦ IIS/Cassini support
Ease of Deployment
Security Features
◦ Evidence-based security
◦ Code access security
◦ The verification process
◦ Role-based security
◦ Cryptography
◦ Application domains
9. Advantages of CLRAdvantages of CLR
Support for developer services (debugging)
Interoperation between managed code and
unmanaged code (COM, DLLs).
Managed code environment
Improved memory handling
Improved “garbage collection”
13. Visual Studio 2005Visual Studio 2005
IDE for .Net development
Dotfuscator encryption tools
Cassini (IIS)
Application Testing Center
Team Suite for project management
Express versions (free)
VB6 to VB.Net conversion wizard
14. .Net Programming Languages.Net Programming Languages
1. Visual Basic.Net
2. C#
3. APL
4. Fortran
5. Pascal
6. C++
7. Haskell
8. Perl
9. Java Language
10.Python
11.COBOL
12.Microsoft JScript
13. RPG
14. Component Pascal
15. Mercury
16. Scheme
17. Curriculum
18. Mondrian
19. SmallTalk
20. Eiffel
21. Oberon
22. Standard ML
23. Forth
24. Oz
15. Informational ResourcesInformational Resources
.Net Overview
http://msdn.microsoft.com/netframework/technologyinfo/overview/
What .Net means to IT Professionals
http://www.microsoft.com/net/business/it_pros.asp
Case Studies:
◦ Continental Airlines
◦ Dollar Rent A Car Systems
◦ U.S. Army Intelligence and Security Command
◦ Scandinavian Airlines
TS2 Seminars
http://www.ts2seminars.com/
19. Hello WorldHello World
DEMO 1: Hello WorldDEMO 1: Hello World
using System;
class Hello
{
static void Main() {
Console.WriteLine("Hello world");
}
}
20. Design Goals of C#Design Goals of C#
The Big IdeasThe Big Ideas
The first “Component Oriented”
language in the C/C++ family
Everything really is an object
Next generation robust and durable
software
Preserving your investment
21. Design Goals of C#Design Goals of C#
InteroperabilityInteroperability
C#C#
VB.NETVB.NET
MC++MC++
JScriptJScript
......
.NET Languages.NET Languages
COMCOM
OLE AutomationOLE Automation
XML/SOAPXML/SOAP
Dynamic Link LibrariesDynamic Link Libraries
P/Invoke and unsafe codeP/Invoke and unsafe code
22. Language FeaturesLanguage Features
Program StructureProgram Structure
Namespaces
◦ Contain types and other namespaces
Type declarations
◦ Classes, structs, interfaces, enums,
and delegates
Members
◦ Constants, fields, methods, properties, indexers, events,
operators, constructors, destructors
Organization
◦ No header files, code written “in-line”
◦ No declaration order dependence
23. Language FeaturesLanguage Features
Program StructureProgram Structure
using System;
namespace System.Collections
{
public class Stack
{
Entry top;
public void Push(object data) {
top = new Entry(top, data);
}
public object Pop() {
if (top == null) throw new InvalidOperationException();
object result = top.data;
top = top.next;
return result;
}
}
}
24. Language FeaturesLanguage Features
Predefined TypesPredefined Types
C# predefined types
◦ Reference object, string
◦ Signed sbyte, short, int, long
◦ Unsigned byte, ushort, uint, ulong
◦ Character char
◦ Floating-point float, double, decimal
◦ Logical bool
Predefined types are simply aliases for system-
provided types
◦ For example, int = System.Int32
25. Language FeaturesLanguage Features
ClassesClasses
Single inheritance
Multiple interface implementation
Class members
◦ Constants, fields, methods, properties,
indexers, events, operators, constructors,
destructors
◦ Static and instance members
◦ Nested types
Member access
◦ Public, protected, internal, private
29. e-Sampark Project
Project e-Sampark was initiated to bring
together the services of all the
departments under one single umbrella
and give citizens of Chandigarh a “multi-
service” - “single-window” experience
apart from eradicating the undue
harassment met by the citizens due to
lack of transparency.
30. Objectives
The objectives of this project are :
Provide hassle free one-stop solution to
the citizen
Minimize multiple interaction points for
the citizen and hence reducing the
wastage of their valuable time
Provide better turn around time in
receipt, processing and issue of services
Transparency in delivery of services
CLR also includes the Just-In-Time (JIT) compiler.
KEY MESSAGE: Common Language Runtime
SLIDE SCRIPT:
At the core of the .NET Framework is the Common Language Runtime which provides a managed environment for all languages. The Common Language Runtime is one of the key differentiators of the .NET Framework from everything else. For example, before the .NET Framework, each language had to implement services like memory management or object layout. This means that for anything but the simplest data types, some kind of conversion would definitely would be needed to, let’s say, use a piece of memory allocated in C++ in VB or Java. The Common Language Runtime eliminates these needs, it allows you to inherit a C# class in Visual Basic or COBOL.
Also it is important to note that the CLR is not platform specific, in fact, is part of our strategy to use the CLR to make it easy to develop the next generation of applications to other devices like cell phones or handhelds.
SLIDE TRANSISTION:
ADDITIONAL INFORMATION FOR PRESENTER:
KEY MESSAGE: Explain the process of converting source code to binary code
SLIDE BUILDS: None
SLIDE SCRIPT: Obviously before the IL code can be executed it must be converted into native binary instructions. Converted? Does this mean interpreted? NO! The IL code is compiled and not thrown away. This means that next time the code is requested it is already in the form of machine instructions and thus this mechanism in the log run is far more efficient than an interpreter for example.
The compilation is carried out by a JIT (Just In Time) compiler. Does the compiler compile all of the code in one go? The answer to this question is NO. If this approach was taken there would be a long delay during the applications initialisation, and realistically not all the code within the module will be required in one go. Instead, when the code is loaded a ‘stub’ is connected to each method. When a method is called via the stub the compiler generates the binary native code. This mechanism goes a long way to describing why the compiler is called a ‘JIT’ compiler.
Compiled code is only saved in the same process (run) of an application. And even then it's not guaranteed. we do what's called "code-pitching" which means we through away cold (or little used) JITed code if memory pressure requires it. We do persisted JITed code in the install time scenario.
The benefit for to this system is obviously portability. A couple of things to think about -
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 release a new version of the JIT, it’s possible that this brand spanking 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 plan to offer a tool called PREJIT. This tool will compile your assemblies at install time into native code and save the resultant binary executable code to disk. When the assemblies are next loaded the binary code is already available thus improving startup time and execution speeds.
SLIDE TRANSISTION: Let us get down to writing code for .NET using Visual Studio.NET…
ADDITIONAL INFORMATION FOR PRESENTER:
KEY MESSAGE: Session Prerequisites
SLIDE SCRIPT:
It will help a lot if the audience has previous experience with object oriented programming as we will discuss concepts like inheritance and performance implications of languages that treats everything as an object.
Visual Basic developers maybe will not get some of the points but this session will serve as a good starting point as well.
SLIDE TRANSISTION: what will be covered today
ADDITIONAL INFORMATION FOR PRESENTER:
KEY MESSAGE: Agenda Slide
SLIDE SCRIPT:
As usual, we’ll start with the traditional Hello World. Then we’ll take a step back and explain the main concepts behind the .NET Framework and then drill down again in the C# Language
SLIDE TRANSISTION: Hello World
ADDITIONAL INFORMATION FOR PRESENTER:
KEY MESSAGE: Hello World is really simple in C#!
SLIDE SCRIPT:
The Hello World application is very simple in C#. Some key points:
In C# there is no global methods. Everything belongs to a class.
A method named Main is the entry point for a C# application. Note that Main is spelled with a capital “M”, which is different than C and C++. The reason is that for consistency, all method names start with a capital letter in the .NET Framework
The line using System; means that we’ll be accessing members of the System namespace. In a very rough comparison, a namespace could be translated to a Unit in Turbo Pascal/Delphi or a .LIB file in C/C++. So in the Hello World example, the class Console, which contains the method WriteLine belongs to the System namespace. We could avoid the “using” statement by writing the complete path of the method:System.Console.WriteLine(“Hello World”);
SLIDE TRANSISTION: Agenda
ADDITIONAL INFORMATION FOR PRESENTER:
KEY MESSAGE: Main ideas behind C#: component support, everything is an object, robust and durable software and preserve investments
SLIDE SCRIPT:
First of all, C# was designed from the ground up to support components concepts like events, methods and properties.
Second, everything is an object, which allows us to do some really clean designs.
Third, it was designed to make it easy to create robust and maintainable software
And finally, it should be able to integrate easily with everything that already exists, preserving your investment.
SLIDE TRANSISTION: Let’s start with component support.
ADDITIONAL INFORMATION FOR PRESENTER:
KEY MESSAGE: Leverage C++ knowledge, interoperability and rich class library
SLIDE SCRIPT:
First of all, since C# was based on C++, C++ programmers will adapt really quick.
Second, interoperability is a key theme in the .NET Framework. So it is really easy to integrate C# code with existing applications
Finally, the .NET Framework provides a very, very rich set of services that will make developers really productive.
SLIDE TRANSISTION: Agenda again…
ADDITIONAL INFORMATION FOR PRESENTER:
KEY MESSAGE:
SLIDE SCRIPT:
The typical C# program is made of a namespace, with one or more type declarations, with each of these types (classes, structs, etc…) containing one or more methods, properties, events, etc.
As we mentioned before, C# doesn’t need header files and also there is no order dependences, so you can safely move one class from one file or another, or the order that you reference namespaces doesn’t affect the behaviour of your code.
SLIDE TRANSISTION: Program Structure example
ADDITIONAL INFORMATION FOR PRESENTER:
KEY MESSAGE:
SLIDE SCRIPT:
This is a typical C# class with two methods Push and Pop, declared in a namespace (System.Collections). This is the typical C# program structure.
SLIDE TRANSISTION: Value types and Reference Types
ADDITIONAL INFORMATION FOR PRESENTER:
KEY MESSAGE:
SLIDE SCRIPT:
Even primitive types actually belongs to a namespace. Actually primitive types are just predefined aliases for system provided types. For example int is just an alias to System.Int32 struct in the .NET Framework.
SLIDE TRANSISTION: Classes
ADDITIONAL INFORMATION FOR PRESENTER:
KEY MESSAGE:
SLIDE SCRIPT:
Classes in C# allow single inheritance and multiple interface inheritance. Each class can contain methods, properties, events, indexers, constants, constructors, destructors, operators and members can be static (can be accessed without an object instance) or instance member (require you to have a reference to an object first)
Also, the access can be controlled in four different levels: public (everyone can access), protected (only inherited members can access), private (only members of the class can access) and internal (anyone on the same EXE or DLL can access)
SLIDE TRANSISTION: Structs
ADDITIONAL INFORMATION FOR PRESENTER: