SlideShare a Scribd company logo
C# Programming and  .NET Concepts By S. Nandagopalan www.bitignou.com [email_address]
Books for Reference C# and the .NET Platform (2 Ed) By Andrew Troelsen  Dreamtech Publications Microsoft Visual C# .NET By Mickey Williams Microsoft Press S. Nandagopalan, B I T
Chapter - 1 The Philosophy of .NET S. Nandagopalan, B I T
Objectives Understanding the previous state of affairs The .NET Solution Building blocks of .NET Platform CLR, CTS, and CLS .NET Base Class Libraries S. Nandagopalan, B I T
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 Not a complete OOP (“Object-aware”) – Why? Doesn’t support inheritance No multithreading No parameterized Classes Low-level API calls are complex S. Nandagopalan, B I T
Previous state of affairs… As a Java/J2EE Programmer Use of Java front-to-back during development cycle No language freedom! Pure Java is not suitable for graphic intensive problems (E.g. 3D game) No cross-language integration As a COM Programmer Complex creation of COM types Active Template Library (ATL) Forced to contend with brittle/fragile registration entries Deployment issues S. Nandagopalan, B I T
.NET Solution Full interoperability with existing Win32 Code Existing COM binaries can interoperate with .NET binaries Complete and total language integration Supports cross-language inheritance, exception handling, and debugging Common runtime engine shared by all .NET aware languages A base class library Good object model used by all .NET aware languages No more COM plumbing! No IClassFactory, IUnKnown, IDispatch, etc. Truly simplified deployment model No need to register a binary unit into the system registry Allows multiple versions of same *.dll S. Nandagopalan, B I T
.NET Framework S. Nandagopalan, B I T Operating System Common Language Runtime Base Class Library ADO.NET and XML Common Language Specification Visual Studio.NET ASP.NET Web Forms  Web Services Windows Forms VB C++ C# JScript J#
Building Blocks of .NET CLR (Common Language Runtime) To locate, load, and manage .NET types Automatic memory management, language integration, and type safety CTS (Common Type System) Describes all possible data types and programming constructs supported by the runtime CLS (Common Language Specification) A set of rules that defines a subset of types and specifications S. Nandagopalan, B I T
CLR  (Common Language Runtime) CLR sits on top of OS (same as JVM of Java) CLR loads modules containing executables and executes them Code may be  managed  or unmanaged Managed code consists of instructions in pseudo random code called  CIL  ( Common Intermediate Language ). CIL instructions are  JIT compiled into native machine code at runtime JIT compiled methods reside in cache until the application’s life time Advantages of managed code: type safety, memory management, and code verification security CLR can translate code from C#, J#, C, C++, VB, and Jscript into CIL. CLR doesn’t launch a new process for every application. It launches one process and hosts individual applications in application domains S. Nandagopalan, B I T
Base Class Libraries Encapsulates various primitives like: threads, file IO, graphical rendering, and other interaction with HW devices It also provides: database manipulation, XML integration, Web-enabled front-end. S. Nandagopalan, B I T Common Language Runtime CTS CLS Base Class Libraries Threading Data Access File IO XML/SOAP GUI
C# Almost same as Java No pointers required Automatic memory management (No ‘delete’)  Enumeration, class, structure, etc. Operator overloading allowed Interface-based programming techniques Assign characteristics to types (same as COM IDL) C# can produce code that can run only on .NET environment (unlike COM server or Win32 API) S. Nandagopalan, B I T
Understanding Assemblies Windows applications have dependencies on one or more DLLs These DLLs may contain COM classes registered in System registry When these components are updated, applications may break –  'DLL hell' Solution: .NET Assemblies C# .NET compiler doesn't generate machine code. It is compiled into " assembly "  S. Nandagopalan, B I T
Assembly Intermediate Language (IL/CIL): Same as first pass of compiler. It can't be executed (it is not in binary format) Metadata Describes the assembly contents No need for component registry Each assembly includes information about references to other assemblies E.g. If you have a class called Car in a given assembly, the type metadata describes Car's base class, which interfaces are implemented by Car, description of members of Car. S. Nandagopalan, B I T C# source code C# .NET Compiler Assembly Metadata IL + =
Assembly… When CLR loads your application, it examines your program's metadata to know which external assemblies are required for execution Private assemblies Used by single application Is not shared Most preferred method Shared assemblies Intended for multiple applications Global Assembly Cache Manifest The metadata of assemblies: version, list of externally defined assemblies, etc. S. Nandagopalan, B I T
Example of CIL CIL sits above a specific compiler (C#, J#, etc.) The associated compiler emits CIL instructions using System; namespace Calculator {   public class CalcApp  {   public static void Main(string[] args) { Calc c = new Calc(); int ans = c.Add(10, 84); Console.WriteLine(ans); Console.ReadLine(); } } public class Calc {   public int Add(int x, int y)   { return x + y; } } } All .NET aware languages   emit same CIL instructions S. Nandagopalan, B I T
CIL of Add() Method .method public hidebysig instance int32  Add(int32 x, int32 y) cil managed { // Code size  8 (0x8) .maxstack  2 .locals init ([0] int32 CS$00000003$00000000) IL_0000:  ldarg.1 IL_0001:  ldarg.2 IL_0002:  add IL_0003:  stloc.0 IL_0004:  br.s  IL_0006 IL_0006:  ldloc.0 IL_0007:  ret } // end of method Calc::Add S. Nandagopalan, B I T
Manifest .assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )  // .z\V.4.. .ver 1:0:5000:0 } .assembly ConsoleApplication1 { .hash algorithm 0x00008004 .ver 1:0:2058:39833 } .module ConsoleApplication1.exe // MVID: {51BE4F31-CBD0-4AE6-BC9D-F9A4976795FD} .imagebase 0x00400000 .subsystem 0x00000003 .file alignment 4096 .corflags 0x00000001 // Image base: 0x070b0000 S. Nandagopalan, B I T External Assembly
CIL to Execution Jitter compiles CIL instructions on the fly into corresponding machine code and cache it. This is useful for not recompiling, if the same method is called again S. Nandagopalan, B I T CIL JIT Desktop Pocket PC Server
Common Type System (CTS) CTS is a formal specification that describes how a given  type  must be defined for CLR CTS Class Type CTS Structure Type CTS Interface Type CTS Enumeration type CTS Delegate type S. Nandagopalan, B I T
CTS Class Type Same as C++ class Can contain members: methods, properties, events, etc. Support for abstract members that define a polymorphic interface for derived classes Multiple inheritance is not allowed S. Nandagopalan, B I T
CTS Class Characteristics "sealed"?  – sealed classes can't function as 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. S. Nandagopalan, B I T
CTS Structure types Same as C/C++  Derived from a common base class System.ValueType CTS Enumeration type To group name/value pairs under a specific name Default Storage: System.Int32 (could be changed) CTS Interface Type Same as pure abstract class of C++ A description of work that a derived class can perform Similar to a class, but can never be instantiated CTS Delegate type Same as C's function pointer  ( System.MulticastDelegate) Useful for event handling (ASP .NET)
Intrinsic CTS Data Types S. Nandagopalan, B I T .NET Base Type 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
Common Language Specification  (CLS) Set of guidelines that describe the minimal and complete set of features a given .NET aware compiler must support C# uses  +  for concatenation whereas VB .NET uses  & C# allows operator overloading but VB .NET does not! The void functions may differ in syntax: ' VB .NET // C# Public Sub Foo() public void Foo() '……. { ……. } End Sub S. Nandagopalan, B I T
CLS Compliance S. Nandagopalan, B I T 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
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; } } Once a method is CLS compliant, then all the .NET aware languages can interact with that implementation S. Nandagopalan, B I T
CLR .NET  Source  Code Base Class Libraries (mscorlib.dll) .NET Execution Engine Class Loader Jitter Platform  Specific code Execute .NET Compiler DLL or EXE (CIL) mscoree.dll mscoree.dll MicroSoft Common  Object Runtime Execution Engine
.NET Namespace MFC, Java, VB 6.0 have predefined set of classes; C# doesn't  C# uses namespace concept Any language targeting the .NET runtime makes use of the same namespaces and same types as C# System is the root namespace S. Nandagopalan, B I T
Example in C# using System; public Class MyApp { public static void Main() { Console.WriteLine("Hello World");  } } S. Nandagopalan, B I T System Namespace Console class in System Namespace
Example in VB .NET Imports System Public Module MyApp Sub Main() Console.WriteLine("Hello World") End Sub End Module S. Nandagopalan, B I T
Example in Managed C++ #using <mscorlib.dll> using namespace System; void Main() { Console::WriteLine(&quot;Hello World&quot;);  } S. Nandagopalan, B I T
Sample .NET namespaces S. Nandagopalan, B I T System primitive types, garbage collection, etc System.Collections Container objects: ArrayList, Queue, etc. System.Data System.Data.Common System.Data.OleDb System.Data.SqlClient For Database manipulations  ADO .NET System.IO file IO, buffering, etc. System.Drawing System.Drawing.2D GDI+ primitives, bitmaps, fonts, icons, etc. System.Threading Threads
Demo Console Application Windows Application Graphics  S. Nandagopalan, B I T
End of  Chapter 1 S. Nandagopalan, B I T

More Related Content

PPT
Abstract data types
Tony Nguyen
 
PPTX
Introduction to C Programming
Amr Ali (ISTQB CTAL Full, CSM, ITIL Foundation)
 
PPTX
07. Virtual Functions
Haresh Jaiswal
 
PPT
Presentation On Com Dcom
Bharat Kumar Katur
 
PPTX
Exception | How Exceptions are Handled in MIPS architecture
babuece
 
PDF
Security in GSM
Dr. Ramchandra Mangrulkar
 
DOC
Error Handling in Compiler Design.typeso
BhuvaneswariR27
 
PPTX
Java packages
BHUVIJAYAVELU
 
Abstract data types
Tony Nguyen
 
07. Virtual Functions
Haresh Jaiswal
 
Presentation On Com Dcom
Bharat Kumar Katur
 
Exception | How Exceptions are Handled in MIPS architecture
babuece
 
Security in GSM
Dr. Ramchandra Mangrulkar
 
Error Handling in Compiler Design.typeso
BhuvaneswariR27
 
Java packages
BHUVIJAYAVELU
 

What's hot (20)

PPT
Encapsulation
FALLEE31188
 
PPTX
Single pass assembler
Bansari Shah
 
PPTX
Symbol Table
Akhil Kaushik
 
PPTX
Register Reference Instructions | Computer Science
Transweb Global Inc
 
PDF
Difference between cts and cls
Umar Ali
 
PDF
Control Flow Analysis
Edgar Barbosa
 
PDF
Bus structure in Computer Organization.pdf
mvpk14486
 
PPT
Schiller2
Kesavaraj Selvaraju
 
PPT
Composition in OOP
Huba Akhtar
 
PPTX
4.7. chomskian hierarchy of languages
Sampath Kumar S
 
PPT
C# Exceptions Handling
sharqiyem
 
PPT
Programming Paradigms
Directi Group
 
PPTX
Intermediate code- generation
rawan_z
 
PPT
C++ Function
Hajar
 
PPSX
Congestion avoidance in TCP
selvakumar_b1985
 
ODP
White box ppt
Chintakunta Hariteja
 
DOCX
C language industrial training report
Raushan Pandey
 
DOCX
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
venkatapranaykumarGa
 
PPTX
Chapter 4 Embedded System: Application and Domain Specific
Moe Moe Myint
 
PPTX
Cross layer design and optimization
DANISHAMIN950
 
Encapsulation
FALLEE31188
 
Single pass assembler
Bansari Shah
 
Symbol Table
Akhil Kaushik
 
Register Reference Instructions | Computer Science
Transweb Global Inc
 
Difference between cts and cls
Umar Ali
 
Control Flow Analysis
Edgar Barbosa
 
Bus structure in Computer Organization.pdf
mvpk14486
 
Composition in OOP
Huba Akhtar
 
4.7. chomskian hierarchy of languages
Sampath Kumar S
 
C# Exceptions Handling
sharqiyem
 
Programming Paradigms
Directi Group
 
Intermediate code- generation
rawan_z
 
C++ Function
Hajar
 
Congestion avoidance in TCP
selvakumar_b1985
 
White box ppt
Chintakunta Hariteja
 
C language industrial training report
Raushan Pandey
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
venkatapranaykumarGa
 
Chapter 4 Embedded System: Application and Domain Specific
Moe Moe Myint
 
Cross layer design and optimization
DANISHAMIN950
 
Ad

Viewers also liked (20)

PPT
Introduction To Dotnet
SAMIR BHOGAYTA
 
PPSX
Introduction to .net framework
Arun Prasad
 
PPT
.Net Session Overview
Logu Thanigachalam
 
PDF
Diving in OOP (Day 6): Understanding Enums in C# (A Practical Approach)
Akhil Mittal
 
PPT
Basic c#
kishore4268
 
PDF
Lesson 2 Understanding Types And Usage In Dot Net
nbaveja
 
PPTX
Fluent interface in c#
Dror Helper
 
PPTX
.Net Assemblies
Muhammad Kamran Rafi
 
PDF
Lesson 1 Understanding Dot Net Framework
nbaveja
 
PDF
The how-dare-you-call-me-an-idiot’s guide to the .NET Standard (NDC London 2017)
citizenmatt
 
PDF
PHP Basic & Variables
M.Zalmai Rahmani
 
PPTX
Lesson 3: Variables and Expressions
"Filniño Edmar Ambos"
 
PPTX
Introduction to asp .net
umesh patil
 
PPTX
dot net technology
Imran Khan
 
PDF
Microsoft .NET Platform
Peter R. Egli
 
PPT
C# Tutorial MSM_Murach chapter-15-slides
Sami Mut
 
PDF
Overview of Microsoft .Net Remoting technology
Peter R. Egli
 
PPT
Dotnet framework
Nitu Pandey
 
PPT
Nakov - .NET Framework Overview - English
Svetlin Nakov
 
PDF
Dotnet basics
Mir Majid
 
Introduction To Dotnet
SAMIR BHOGAYTA
 
Introduction to .net framework
Arun Prasad
 
.Net Session Overview
Logu Thanigachalam
 
Diving in OOP (Day 6): Understanding Enums in C# (A Practical Approach)
Akhil Mittal
 
Basic c#
kishore4268
 
Lesson 2 Understanding Types And Usage In Dot Net
nbaveja
 
Fluent interface in c#
Dror Helper
 
.Net Assemblies
Muhammad Kamran Rafi
 
Lesson 1 Understanding Dot Net Framework
nbaveja
 
The how-dare-you-call-me-an-idiot’s guide to the .NET Standard (NDC London 2017)
citizenmatt
 
PHP Basic & Variables
M.Zalmai Rahmani
 
Lesson 3: Variables and Expressions
"Filniño Edmar Ambos"
 
Introduction to asp .net
umesh patil
 
dot net technology
Imran Khan
 
Microsoft .NET Platform
Peter R. Egli
 
C# Tutorial MSM_Murach chapter-15-slides
Sami Mut
 
Overview of Microsoft .Net Remoting technology
Peter R. Egli
 
Dotnet framework
Nitu Pandey
 
Nakov - .NET Framework Overview - English
Svetlin Nakov
 
Dotnet basics
Mir Majid
 
Ad

Similar to 1.Philosophy of .NET (20)

DOCX
C# Unit 1 notes
Sudarshan Dhondaley
 
PPTX
Introduction to .NET by QuontraSolutions
QUONTRASOLUTIONS
 
PPT
Intro dotnet
shuklagirish
 
PPT
Intro dotnet
shuklagirish
 
PPT
Intro dotnet
shuklagirish
 
PPT
Intro dotnet
shuklagirish
 
PPT
COM Introduction
Roy Antony Arnold G
 
PPT
C#_01_CLROverview.ppt
MarcEdwards35
 
PPTX
Presentation1
kpkcsc
 
PPTX
Session2 (3)
DrUjwala1
 
PPTX
1. Introduction to C# Programming Langua
KhinLaPyaeWoon1
 
PPT
Concepts of Asp.Net
vidyamittal
 
DOCX
Srgoc dotnet_new
Gaurav Singh
 
PPT
Basics of c# by sabir
Sabir Ali
 
PPT
CSharp_01_CLROverview_and Introductionc#
Ranjithsingh20
 
PPT
Intro.net
singhadarsh
 
PPT
Introdot Netc Sharp En
Gregory Renard
 
PDF
tybsc it asp.net full unit 1,2,3,4,5,6 notes
WE-IT TUTORIALS
 
PPT
C Sharp Jn
guest58c84c
 
PPT
C Sharp Jn
jahanullah
 
C# Unit 1 notes
Sudarshan Dhondaley
 
Introduction to .NET by QuontraSolutions
QUONTRASOLUTIONS
 
Intro dotnet
shuklagirish
 
Intro dotnet
shuklagirish
 
Intro dotnet
shuklagirish
 
Intro dotnet
shuklagirish
 
COM Introduction
Roy Antony Arnold G
 
C#_01_CLROverview.ppt
MarcEdwards35
 
Presentation1
kpkcsc
 
Session2 (3)
DrUjwala1
 
1. Introduction to C# Programming Langua
KhinLaPyaeWoon1
 
Concepts of Asp.Net
vidyamittal
 
Srgoc dotnet_new
Gaurav Singh
 
Basics of c# by sabir
Sabir Ali
 
CSharp_01_CLROverview_and Introductionc#
Ranjithsingh20
 
Intro.net
singhadarsh
 
Introdot Netc Sharp En
Gregory Renard
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
WE-IT TUTORIALS
 
C Sharp Jn
guest58c84c
 
C Sharp Jn
jahanullah
 

1.Philosophy of .NET

  • 1. C# Programming and .NET Concepts By S. Nandagopalan www.bitignou.com [email_address]
  • 2. Books for Reference C# and the .NET Platform (2 Ed) By Andrew Troelsen Dreamtech Publications Microsoft Visual C# .NET By Mickey Williams Microsoft Press S. Nandagopalan, B I T
  • 3. Chapter - 1 The Philosophy of .NET S. Nandagopalan, B I T
  • 4. Objectives Understanding the previous state of affairs The .NET Solution Building blocks of .NET Platform CLR, CTS, and CLS .NET Base Class Libraries S. Nandagopalan, B I T
  • 5. 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 Not a complete OOP (“Object-aware”) – Why? Doesn’t support inheritance No multithreading No parameterized Classes Low-level API calls are complex S. Nandagopalan, B I T
  • 6. Previous state of affairs… As a Java/J2EE Programmer Use of Java front-to-back during development cycle No language freedom! Pure Java is not suitable for graphic intensive problems (E.g. 3D game) No cross-language integration As a COM Programmer Complex creation of COM types Active Template Library (ATL) Forced to contend with brittle/fragile registration entries Deployment issues S. Nandagopalan, B I T
  • 7. .NET Solution Full interoperability with existing Win32 Code Existing COM binaries can interoperate with .NET binaries Complete and total language integration Supports cross-language inheritance, exception handling, and debugging Common runtime engine shared by all .NET aware languages A base class library Good object model used by all .NET aware languages No more COM plumbing! No IClassFactory, IUnKnown, IDispatch, etc. Truly simplified deployment model No need to register a binary unit into the system registry Allows multiple versions of same *.dll S. Nandagopalan, B I T
  • 8. .NET Framework S. Nandagopalan, B I T Operating System Common Language Runtime Base Class Library ADO.NET and XML Common Language Specification Visual Studio.NET ASP.NET Web Forms Web Services Windows Forms VB C++ C# JScript J#
  • 9. Building Blocks of .NET CLR (Common Language Runtime) To locate, load, and manage .NET types Automatic memory management, language integration, and type safety CTS (Common Type System) Describes all possible data types and programming constructs supported by the runtime CLS (Common Language Specification) A set of rules that defines a subset of types and specifications S. Nandagopalan, B I T
  • 10. CLR (Common Language Runtime) CLR sits on top of OS (same as JVM of Java) CLR loads modules containing executables and executes them Code may be managed or unmanaged Managed code consists of instructions in pseudo random code called CIL ( Common Intermediate Language ). CIL instructions are JIT compiled into native machine code at runtime JIT compiled methods reside in cache until the application’s life time Advantages of managed code: type safety, memory management, and code verification security CLR can translate code from C#, J#, C, C++, VB, and Jscript into CIL. CLR doesn’t launch a new process for every application. It launches one process and hosts individual applications in application domains S. Nandagopalan, B I T
  • 11. Base Class Libraries Encapsulates various primitives like: threads, file IO, graphical rendering, and other interaction with HW devices It also provides: database manipulation, XML integration, Web-enabled front-end. S. Nandagopalan, B I T Common Language Runtime CTS CLS Base Class Libraries Threading Data Access File IO XML/SOAP GUI
  • 12. C# Almost same as Java No pointers required Automatic memory management (No ‘delete’) Enumeration, class, structure, etc. Operator overloading allowed Interface-based programming techniques Assign characteristics to types (same as COM IDL) C# can produce code that can run only on .NET environment (unlike COM server or Win32 API) S. Nandagopalan, B I T
  • 13. Understanding Assemblies Windows applications have dependencies on one or more DLLs These DLLs may contain COM classes registered in System registry When these components are updated, applications may break – 'DLL hell' Solution: .NET Assemblies C# .NET compiler doesn't generate machine code. It is compiled into &quot; assembly &quot; S. Nandagopalan, B I T
  • 14. Assembly Intermediate Language (IL/CIL): Same as first pass of compiler. It can't be executed (it is not in binary format) Metadata Describes the assembly contents No need for component registry Each assembly includes information about references to other assemblies E.g. If you have a class called Car in a given assembly, the type metadata describes Car's base class, which interfaces are implemented by Car, description of members of Car. S. Nandagopalan, B I T C# source code C# .NET Compiler Assembly Metadata IL + =
  • 15. Assembly… When CLR loads your application, it examines your program's metadata to know which external assemblies are required for execution Private assemblies Used by single application Is not shared Most preferred method Shared assemblies Intended for multiple applications Global Assembly Cache Manifest The metadata of assemblies: version, list of externally defined assemblies, etc. S. Nandagopalan, B I T
  • 16. Example of CIL CIL sits above a specific compiler (C#, J#, etc.) The associated compiler emits CIL instructions using System; namespace Calculator { public class CalcApp { public static void Main(string[] args) { Calc c = new Calc(); int ans = c.Add(10, 84); Console.WriteLine(ans); Console.ReadLine(); } } public class Calc { public int Add(int x, int y) { return x + y; } } } All .NET aware languages emit same CIL instructions S. Nandagopalan, B I T
  • 17. CIL of Add() Method .method public hidebysig instance int32 Add(int32 x, int32 y) cil managed { // Code size 8 (0x8) .maxstack 2 .locals init ([0] int32 CS$00000003$00000000) IL_0000: ldarg.1 IL_0001: ldarg.2 IL_0002: add IL_0003: stloc.0 IL_0004: br.s IL_0006 IL_0006: ldloc.0 IL_0007: ret } // end of method Calc::Add S. Nandagopalan, B I T
  • 18. Manifest .assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 1:0:5000:0 } .assembly ConsoleApplication1 { .hash algorithm 0x00008004 .ver 1:0:2058:39833 } .module ConsoleApplication1.exe // MVID: {51BE4F31-CBD0-4AE6-BC9D-F9A4976795FD} .imagebase 0x00400000 .subsystem 0x00000003 .file alignment 4096 .corflags 0x00000001 // Image base: 0x070b0000 S. Nandagopalan, B I T External Assembly
  • 19. CIL to Execution Jitter compiles CIL instructions on the fly into corresponding machine code and cache it. This is useful for not recompiling, if the same method is called again S. Nandagopalan, B I T CIL JIT Desktop Pocket PC Server
  • 20. Common Type System (CTS) CTS is a formal specification that describes how a given type must be defined for CLR CTS Class Type CTS Structure Type CTS Interface Type CTS Enumeration type CTS Delegate type S. Nandagopalan, B I T
  • 21. CTS Class Type Same as C++ class Can contain members: methods, properties, events, etc. Support for abstract members that define a polymorphic interface for derived classes Multiple inheritance is not allowed S. Nandagopalan, B I T
  • 22. CTS Class Characteristics &quot;sealed&quot;? – sealed classes can't function as 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. S. Nandagopalan, B I T
  • 23. CTS Structure types Same as C/C++ Derived from a common base class System.ValueType CTS Enumeration type To group name/value pairs under a specific name Default Storage: System.Int32 (could be changed) CTS Interface Type Same as pure abstract class of C++ A description of work that a derived class can perform Similar to a class, but can never be instantiated CTS Delegate type Same as C's function pointer ( System.MulticastDelegate) Useful for event handling (ASP .NET)
  • 24. Intrinsic CTS Data Types S. Nandagopalan, B I T .NET Base Type 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
  • 25. Common Language Specification (CLS) Set of guidelines that describe the minimal and complete set of features a given .NET aware compiler must support C# uses + for concatenation whereas VB .NET uses & C# allows operator overloading but VB .NET does not! The void functions may differ in syntax: ' VB .NET // C# Public Sub Foo() public void Foo() '……. { ……. } End Sub S. Nandagopalan, B I T
  • 26. CLS Compliance S. Nandagopalan, B I T 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
  • 27. 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; } } Once a method is CLS compliant, then all the .NET aware languages can interact with that implementation S. Nandagopalan, B I T
  • 28. CLR .NET Source Code Base Class Libraries (mscorlib.dll) .NET Execution Engine Class Loader Jitter Platform Specific code Execute .NET Compiler DLL or EXE (CIL) mscoree.dll mscoree.dll MicroSoft Common Object Runtime Execution Engine
  • 29. .NET Namespace MFC, Java, VB 6.0 have predefined set of classes; C# doesn't C# uses namespace concept Any language targeting the .NET runtime makes use of the same namespaces and same types as C# System is the root namespace S. Nandagopalan, B I T
  • 30. Example in C# using System; public Class MyApp { public static void Main() { Console.WriteLine(&quot;Hello World&quot;); } } S. Nandagopalan, B I T System Namespace Console class in System Namespace
  • 31. Example in VB .NET Imports System Public Module MyApp Sub Main() Console.WriteLine(&quot;Hello World&quot;) End Sub End Module S. Nandagopalan, B I T
  • 32. Example in Managed C++ #using <mscorlib.dll> using namespace System; void Main() { Console::WriteLine(&quot;Hello World&quot;); } S. Nandagopalan, B I T
  • 33. Sample .NET namespaces S. Nandagopalan, B I T System primitive types, garbage collection, etc System.Collections Container objects: ArrayList, Queue, etc. System.Data System.Data.Common System.Data.OleDb System.Data.SqlClient For Database manipulations ADO .NET System.IO file IO, buffering, etc. System.Drawing System.Drawing.2D GDI+ primitives, bitmaps, fonts, icons, etc. System.Threading Threads
  • 34. Demo Console Application Windows Application Graphics S. Nandagopalan, B I T
  • 35. End of Chapter 1 S. Nandagopalan, B I T