Professional Documents
Culture Documents
.NET Concepts
By Andrew Troelsen
Dreamtech Publications
By Mickey Williams
Microsoft Press
Chapter - 1
Objectives
Understanding the previous state of
affairs
The .NET Solution
Building blocks of .NET Platform
Understanding the
previous state of affairs
As a C/Win32 API Programmer
It is complex
C is a short/abrupt language
Manual memory management, ugly pointer
arithmetic, ugly syntactic constructs
Not a OO language
As a C++/MFC Programmer
Root is C
C++ with MFC is still complex and error-prone
As a VB 6 Programmer
As a COM Programmer
.NET Solution
Full interoperability with existing Win32 Code
languages
A base class library
.NET Framework
VB
C++
C#
JScript
J#
Visual Studio.NET
ASP.NET
Web Forms Web Services
CLR
10
GUI
Threading
File IO
XML/SOAP
CLS
11
C#
Understanding Assemblies
Windows applications have dependencies
13
Understanding Assemblies
An assembly is a logical collection of one or
more EXE or DLL files containing an
application code & resources
.NET binaries not described using com
libraries & not registered into system
registry
.NET binaries contain platform agnostic
intermediate language (IL) & type metada
14
Assembly
C# source code
Metadata
C# .NET Compiler
IL
Assembly
Assembly
When CLR loads your application, it examines your
Is not shared
Multi-file assemblies
18
Example of CIL
using System;
namespace Calculator
{
public class CalcApp
{
19
21
22
CIL to Execution
Desktop
CIL
JIT
Server
Pocket PC
24
25
26
Manifest
External
Assembly
// .z\V.4..
27
29
30
base classes
Implement any interfaces? An interface
is a collection of abstract members
Abstract or Concrete? Abstract classes
(to define common behaviors for derived)
can't be created directly but concrete
classes can.
Visibility? visibility attribute to know
whether external assemblies can use it.
31
Same as C/C++
33
34
C# Type
System.Byte
Byte
System.SByte
sbyte
System.Int16
short
System.Int32
int
System.Int64
long
System.UInt64
ulong
System.Single
float
System.Double
double
System.Object
object
System.String
string
System.Boolean
bool
36
(CLS)
// C#
(CLS)
38
CLS Compliance
C# Type
CLS Compliance
byte
Yes
sbyte
No
short
Yes
int
Yes
long
Yes
ulong
No
float
Yes
double
Yes
object
Yes
string
Yes
char
Yes
bool
Yes
39
Example
public class Calc
{
// CLS compliant
public int Add(int x, int y)
{ return x + y; }
// Not CLS compliant
public ulong Add(ulong x, ulong y)
{ return x + y; }
}
40
framework
CLR is a runtime environment - c# &
other .net languages are executed
Supports cross language interoperability
The fig shows major components of CLR
CLR
CTS
IL
Execution support function
garbage collection
class loader
memory layout
41
CLR
.NET
Source
Code
.NET Compiler
DLL or EXE
(CIL)
mscoree.dll
Class Loader
Base Class
Libraries
(mscorlib.dll)
Jitter
Platform
Specific code
mscoree.dll
MicroSoft Common
Object Runtime Execution Engine
Execute
.NET Execution Engine
.NET Namespace
MFC, Java, VB 6.0 have predefined set of
classes; C# doesn't
Example in C#
System Namespace
using System;
public Class MyApp
{
Console class in
public static void Main() System
Namespace
{
Console.WriteLine("Hello World");
}
}
45
Example in VB .NET
Imports System
Public Module MyApp
Sub Main()
Console.WriteLine("Hello World")
End Sub
End Module
46
System.Collections
System.Data
System.Data.Common
System.Data.OleDb
System.Data.SqlClient
System.IO
System.Drawing
System.Drawing.2D
System.Threading
Threads
48
Using ildasm.exe
Intermediate Language Disassembler
utility
It allows to load up any .NET
assembly & investigate its contents,
including associated manifest, CIL &
type metadata
ildasm.exe installed under c:\program
files\ microsoft visual studio8\
SDK\v2.0\bin
53
Using ildasm.exe
Viewing CIL code double click the
54
Questions
What is .net Framework? With a neat diagram
Questions
Write short notes on: .net binaries & .net
type metadata
Explain briefly about ILDASM?
Briefly discuss the state of affairs that
eventually led to the .NET platform. What is
the .NET solution and what C# brings to
the table.
Write the difference b/w single-file &
multifile assemblies.
What are namespaces? List and explain the
purpose of at least five namespaces.
57
End of Chapter 1
58