SlideShare a Scribd company logo
1 of 35
Programming in C#
CSE 4253
Prof. Roger Crawfis
Course Overview
 1-credit pass/no-pass brief introduction to C#.
 Covers the .NET framework, (most of) the C#
language and some of the most useful .NET
API’s.
 Should not be your first programming class.
 Assume you know C++ and/or Java and basic
object-oriented or component-based programming.
 Requires (lots of) practice / reading.
 C# and .NET cannot be learned thoroughly in this
brief course.
S/U Details
 Requirements for the course
 Do all assignments (including worksheets).
 If you know C# already, fine get the stuff done at your
own pace for credit.
 Learning
 If you want to know some subtle points, better
programming, watch the lectures.
 If stuck make sure you do the worksheets and watch the
lectures.
 Assignments are S/U
 You will not be given a detailed grade
 Show me that you understand the concepts, and can
write C# code
Syllabus
 Background, history, CLI, CIL, CLR, CTS, …
 C# Types
 Primitive types, Classes, Properties, Interfaces,
Delegates, Events, Generic types.
 C# language features
 foreach, yield, events, is/as (type casting), lock.
 Common Interfaces
 Iterators, equality and comparison
 Base Class Library
Programming in C#
C# History
CSE 4253
Prof. Roger Crawfis
History of C#
 Developed by Microsoft.
 Based on Java and C++, but has many
additional extensions.
 Java and C# are both being updated to
keep up with each other.
 Cross-development with Visual Basic,
Visual C++, F#, IronPython, and many
other .NET languages.
 See: http://en.wikipedia.org/wiki/List_of_CLI_languages
Classification of C#
 Wikipedia.org definition.
 Object-oriented.
 Primarily imperative or procedural.
 LINQ adds some functional programming
language capabilities.
 Structured (as opposed to monolithic).
 Strongly typed.
 ISO and ECMA standardized.
Microsoft’s .NET Technologies
The Class Libraries
 The common classes that are used in
many programs
 System.Console.WriteLine
 XML, Networking, Filesystem, Crypto,
containers
 Can inherit from many of these classes
 Many languages run on .NET framework
 C#, C++, J#, Visual Basic
 even have Python (see IronPython)
.NET History
The Class Libraries
IDE’s and CLI Implementations
 Visual C# http://www.microsoft.com/express/2008/
 in MSDNAA
 must be version 2008: we need C# 3.0
 Mono: http://www.go-mono.com
 Open Source for Linux: not quite at 2.0
 Rotor: http://msdn.microsoft.com/net/sscli
 Shared Source for Windows (through 2.0)
 Use to work on BSD / OS X, too
 Portable.NET: http://www.dotgnu.org
 yet another open source implementation
Programming in C#
CLR, CLI, oh my!
CSE 459.24
Prof. Roger Crawfis
CLR and JIT compiling.
 C#, like Java, is
executed indirectly
through an abstract
computer architecture
called the CLR.
 CLR => Common
Language Runtime.
 Abstract, but well
defined.
 C# programs are
compiled to an IL.
 Also called MSIL, CIL
(Common Intermediate
Language) or bytecode. http://msdn2.microsoft.com/en-us/library/z1zx9t92(VS.80).aspx
CLR and JIT compiling.
 The CLR transforms the CIL to assembly
instructions for a particular hardware
architecture.
 This is termed jit’ing or Just-in-time
compiling.
 Some initial performance cost, but the jitted
code is cached for further execution.
 The CLR can target the specific architecture
in which the code is executing, so some
performance gains are possible.
CLR and JIT compiling.
 All .NET languages compile to the same
CIL.
 Each language actually uses only a
subset of the CIL.
 The least-common denominator is the
Common Language Specification (CLS).
 So, if you want to use your C#
components in Visual Basic you need to
program to the CLS.
CLR versus CLI.
 CLR is actually an
implementation by
Microsoft of the CLI
(Common Language
Infrastructure) .
 CLI is an open
specification.
 CLR is really a
platform specific
implementation.
from wikipedia.org
The CLR Architecture
Class Loader
MSIL to Native
Compilers (JIT)
Code
Manager
Garbage
Collector (GC)
Security Engine Debug Engine
Type Checker Exception Manager
Thread Support COM Marshaler
Base Class Library Support
From MSDN
Common Language Infrastructure.
 CLI allows for cross-language
development.
 Four components:
 Common Type System (CTS)
 Meta-data in a language agnostic fashion.
 Common Language Specification –
behaviors that all languages need to follow.
 A Virtual Execution System (VES).
Common Type System (CTS)
 A specification for how types are defined and
how they behave.
 no syntax specified
 A type can contain zero or more members:
 Field
 Method
 Property
 Event
 We will go over these more throughout the
quarter.
Common Type System (CTS)
 CTS also specifies the rules for visibility and
access to members of a type:
 Private
 Family
 Family and Assembly
 Assembly
 Family or Assembly
 Public
 We will go over these more throughout the
quarter.
Common Type System (CTS)
 Other rules
 Object life-time
 Inheritance
 Equality (through System.Object)
Common Type System (CTS)
 Languages often define aliases
 For example
 CTS defines System.Int32 – 4 byte integer
 C# defines int as an alias of System.Int32
 C# aliases System.String as string.
Common Type System (CTS)
From MSDN
Common Language System
 A specification of language features
 how methods may be called
 when constructors are called
 subset of the types in CTS which are allowed
 For example
 Code that takes UInt32 in a public method
 UInt32 is not in the CLS
 Can mark classes as CLS-compliant
 not marked is assumed to mean not compliant
CLS versus CLR
CLR via C#, Jeffrey Richter
Built-in Types
C#
CTS type
(FCL name)
CLS compliant
int System.Int32 yes
uint System.UInt32 no
sbyte System.SByte no
byte System.Byte yes
short System.Int16 yes
ushort System.UInt16 no
long System.Int64 yes
ulong System.UInt64 no
float System.Single yes
double System.Double yes
decimal System.Decimal yes
char System.Char yes
string System.String yes
object System.Object yes
Blittable types
 Most of these types are blittable,
meaning their memory layout is
consistent across languages and hence,
support interoperability.
 The types bool, char, object and string
are not and must be Marshaled when
using these between languages.
 Single dimensional arrays of blittable
types are also blittable.
Programming in C#
Assemblies
CSE 494R
(proposed course for 459 Programming in C#)
Prof. Roger Crawfis
Assemblies
 Code contained in files called “assemblies”
 code and metadata
 .exe or .dll as before
 Executable needs a class with a “Main” method:
 public static void Main(string[] args)
 types
 local: local assembly, not accessible by others
 shared: well-known location, can be GAC
 strong names: use crypto for signatures
 then can add some versioning and trust
PE executable file
Structure of PE file
PE header
MS IL instructions
Metadata
native instructions
Entry point address Other initial settings
e.g., x86 instructions
Type Tables Attributes Security
Manifests and Assemblies
First C# Program
using System;
namespace Test
{
class ExampleClass
{
static void Main()
{
System.Console.WriteLine("Hello, world!");
}
}
}
Constructions of Note
 using
 like import in Java: bring in namespaces
 namespace
 disambiguation of names
 like Internet hierarchical names and C++
naming
 class
 like in C++ or Java
 single inheritance up to object
Constructions of Note
 static void Main()
 Defines the entry point for an assembly.
 Four different overloads – taking string arguments
and returning int’s.
 Console.Write(Line)
 Takes a formatted string: “Composite Format”
 Indexed elements: e.g., {0}
 can be used multiple times
 only evaluated once
 {index [,alignment][:formatting]}

More Related Content

Similar to C#_01_CLROverview.ppt

Common language runtime clr
Common language runtime clrCommon language runtime clr
Common language runtime clrSanSan149
 
Presentation1
Presentation1Presentation1
Presentation1kpkcsc
 
Introductionto .netframework by Priyanka Pinglikar
Introductionto .netframework by Priyanka PinglikarIntroductionto .netframework by Priyanka Pinglikar
Introductionto .netframework by Priyanka PinglikarPriyankaPinglikar
 
CS4443 - Modern Programming Language - I Lecture (1)
CS4443 - Modern Programming Language - I Lecture (1)CS4443 - Modern Programming Language - I Lecture (1)
CS4443 - Modern Programming Language - I Lecture (1)Dilawar Khan
 
.Net framework components by naveen kumar veligeti
.Net framework components by naveen kumar veligeti.Net framework components by naveen kumar veligeti
.Net framework components by naveen kumar veligetiNaveen Kumar Veligeti
 
.Net overview|Introduction Of .net
.Net overview|Introduction Of .net.Net overview|Introduction Of .net
.Net overview|Introduction Of .netpinky singh
 
.Net Framework
.Net Framework.Net Framework
.Net FrameworkMohamadKrm
 
Mit4021 c# and .net
Mit4021   c# and .netMit4021   c# and .net
Mit4021 c# and .netsmumbahelp
 
Dotnet interview qa
Dotnet interview qaDotnet interview qa
Dotnet interview qaabcxyzqaz
 
c# usage,applications and advantages
c# usage,applications and advantages c# usage,applications and advantages
c# usage,applications and advantages mohamed drahem
 
Runtime Environment Of .Net Divya Rathore
Runtime Environment Of .Net Divya RathoreRuntime Environment Of .Net Divya Rathore
Runtime Environment Of .Net Divya RathoreEsha Yadav
 
Microsoft .NET Platform
Microsoft .NET PlatformMicrosoft .NET Platform
Microsoft .NET PlatformPeter R. Egli
 
Chapter 1 introduction to .net
Chapter 1 introduction to .netChapter 1 introduction to .net
Chapter 1 introduction to .netRahul Bhoge
 

Similar to C#_01_CLROverview.ppt (20)

Common language runtime clr
Common language runtime clrCommon language runtime clr
Common language runtime clr
 
Presentation1
Presentation1Presentation1
Presentation1
 
Intro.net
Intro.netIntro.net
Intro.net
 
Introductionto .netframework by Priyanka Pinglikar
Introductionto .netframework by Priyanka PinglikarIntroductionto .netframework by Priyanka Pinglikar
Introductionto .netframework by Priyanka Pinglikar
 
The Philosophy of .Net
The Philosophy of .NetThe Philosophy of .Net
The Philosophy of .Net
 
CS4443 - Modern Programming Language - I Lecture (1)
CS4443 - Modern Programming Language - I Lecture (1)CS4443 - Modern Programming Language - I Lecture (1)
CS4443 - Modern Programming Language - I Lecture (1)
 
.Net framework components by naveen kumar veligeti
.Net framework components by naveen kumar veligeti.Net framework components by naveen kumar veligeti
.Net framework components by naveen kumar veligeti
 
.Net overview|Introduction Of .net
.Net overview|Introduction Of .net.Net overview|Introduction Of .net
.Net overview|Introduction Of .net
 
.Net slid
.Net slid.Net slid
.Net slid
 
Microsoft.Net
Microsoft.NetMicrosoft.Net
Microsoft.Net
 
C# note
C# noteC# note
C# note
 
.Net Framework
.Net Framework.Net Framework
.Net Framework
 
Mit4021 c# and .net
Mit4021   c# and .netMit4021   c# and .net
Mit4021 c# and .net
 
Dotnet interview qa
Dotnet interview qaDotnet interview qa
Dotnet interview qa
 
c# usage,applications and advantages
c# usage,applications and advantages c# usage,applications and advantages
c# usage,applications and advantages
 
Runtime Environment Of .Net Divya Rathore
Runtime Environment Of .Net Divya RathoreRuntime Environment Of .Net Divya Rathore
Runtime Environment Of .Net Divya Rathore
 
Microsoft .NET Platform
Microsoft .NET PlatformMicrosoft .NET Platform
Microsoft .NET Platform
 
Chapter 1 introduction to .net
Chapter 1 introduction to .netChapter 1 introduction to .net
Chapter 1 introduction to .net
 
Vb
VbVb
Vb
 
Intro to .NET and Core C#
Intro to .NET and Core C#Intro to .NET and Core C#
Intro to .NET and Core C#
 

Recently uploaded

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 

Recently uploaded (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 

C#_01_CLROverview.ppt

  • 1. Programming in C# CSE 4253 Prof. Roger Crawfis
  • 2. Course Overview  1-credit pass/no-pass brief introduction to C#.  Covers the .NET framework, (most of) the C# language and some of the most useful .NET API’s.  Should not be your first programming class.  Assume you know C++ and/or Java and basic object-oriented or component-based programming.  Requires (lots of) practice / reading.  C# and .NET cannot be learned thoroughly in this brief course.
  • 3. S/U Details  Requirements for the course  Do all assignments (including worksheets).  If you know C# already, fine get the stuff done at your own pace for credit.  Learning  If you want to know some subtle points, better programming, watch the lectures.  If stuck make sure you do the worksheets and watch the lectures.  Assignments are S/U  You will not be given a detailed grade  Show me that you understand the concepts, and can write C# code
  • 4. Syllabus  Background, history, CLI, CIL, CLR, CTS, …  C# Types  Primitive types, Classes, Properties, Interfaces, Delegates, Events, Generic types.  C# language features  foreach, yield, events, is/as (type casting), lock.  Common Interfaces  Iterators, equality and comparison  Base Class Library
  • 5. Programming in C# C# History CSE 4253 Prof. Roger Crawfis
  • 6. History of C#  Developed by Microsoft.  Based on Java and C++, but has many additional extensions.  Java and C# are both being updated to keep up with each other.  Cross-development with Visual Basic, Visual C++, F#, IronPython, and many other .NET languages.  See: http://en.wikipedia.org/wiki/List_of_CLI_languages
  • 7. Classification of C#  Wikipedia.org definition.  Object-oriented.  Primarily imperative or procedural.  LINQ adds some functional programming language capabilities.  Structured (as opposed to monolithic).  Strongly typed.  ISO and ECMA standardized.
  • 9. The Class Libraries  The common classes that are used in many programs  System.Console.WriteLine  XML, Networking, Filesystem, Crypto, containers  Can inherit from many of these classes  Many languages run on .NET framework  C#, C++, J#, Visual Basic  even have Python (see IronPython)
  • 12. IDE’s and CLI Implementations  Visual C# http://www.microsoft.com/express/2008/  in MSDNAA  must be version 2008: we need C# 3.0  Mono: http://www.go-mono.com  Open Source for Linux: not quite at 2.0  Rotor: http://msdn.microsoft.com/net/sscli  Shared Source for Windows (through 2.0)  Use to work on BSD / OS X, too  Portable.NET: http://www.dotgnu.org  yet another open source implementation
  • 13. Programming in C# CLR, CLI, oh my! CSE 459.24 Prof. Roger Crawfis
  • 14. CLR and JIT compiling.  C#, like Java, is executed indirectly through an abstract computer architecture called the CLR.  CLR => Common Language Runtime.  Abstract, but well defined.  C# programs are compiled to an IL.  Also called MSIL, CIL (Common Intermediate Language) or bytecode. http://msdn2.microsoft.com/en-us/library/z1zx9t92(VS.80).aspx
  • 15. CLR and JIT compiling.  The CLR transforms the CIL to assembly instructions for a particular hardware architecture.  This is termed jit’ing or Just-in-time compiling.  Some initial performance cost, but the jitted code is cached for further execution.  The CLR can target the specific architecture in which the code is executing, so some performance gains are possible.
  • 16. CLR and JIT compiling.  All .NET languages compile to the same CIL.  Each language actually uses only a subset of the CIL.  The least-common denominator is the Common Language Specification (CLS).  So, if you want to use your C# components in Visual Basic you need to program to the CLS.
  • 17. CLR versus CLI.  CLR is actually an implementation by Microsoft of the CLI (Common Language Infrastructure) .  CLI is an open specification.  CLR is really a platform specific implementation. from wikipedia.org
  • 18. The CLR Architecture Class Loader MSIL to Native Compilers (JIT) Code Manager Garbage Collector (GC) Security Engine Debug Engine Type Checker Exception Manager Thread Support COM Marshaler Base Class Library Support From MSDN
  • 19. Common Language Infrastructure.  CLI allows for cross-language development.  Four components:  Common Type System (CTS)  Meta-data in a language agnostic fashion.  Common Language Specification – behaviors that all languages need to follow.  A Virtual Execution System (VES).
  • 20. Common Type System (CTS)  A specification for how types are defined and how they behave.  no syntax specified  A type can contain zero or more members:  Field  Method  Property  Event  We will go over these more throughout the quarter.
  • 21. Common Type System (CTS)  CTS also specifies the rules for visibility and access to members of a type:  Private  Family  Family and Assembly  Assembly  Family or Assembly  Public  We will go over these more throughout the quarter.
  • 22. Common Type System (CTS)  Other rules  Object life-time  Inheritance  Equality (through System.Object)
  • 23. Common Type System (CTS)  Languages often define aliases  For example  CTS defines System.Int32 – 4 byte integer  C# defines int as an alias of System.Int32  C# aliases System.String as string.
  • 24. Common Type System (CTS) From MSDN
  • 25. Common Language System  A specification of language features  how methods may be called  when constructors are called  subset of the types in CTS which are allowed  For example  Code that takes UInt32 in a public method  UInt32 is not in the CLS  Can mark classes as CLS-compliant  not marked is assumed to mean not compliant
  • 26. CLS versus CLR CLR via C#, Jeffrey Richter
  • 27. Built-in Types C# CTS type (FCL name) CLS compliant int System.Int32 yes uint System.UInt32 no sbyte System.SByte no byte System.Byte yes short System.Int16 yes ushort System.UInt16 no long System.Int64 yes ulong System.UInt64 no float System.Single yes double System.Double yes decimal System.Decimal yes char System.Char yes string System.String yes object System.Object yes
  • 28. Blittable types  Most of these types are blittable, meaning their memory layout is consistent across languages and hence, support interoperability.  The types bool, char, object and string are not and must be Marshaled when using these between languages.  Single dimensional arrays of blittable types are also blittable.
  • 29. Programming in C# Assemblies CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis
  • 30. Assemblies  Code contained in files called “assemblies”  code and metadata  .exe or .dll as before  Executable needs a class with a “Main” method:  public static void Main(string[] args)  types  local: local assembly, not accessible by others  shared: well-known location, can be GAC  strong names: use crypto for signatures  then can add some versioning and trust
  • 31. PE executable file Structure of PE file PE header MS IL instructions Metadata native instructions Entry point address Other initial settings e.g., x86 instructions Type Tables Attributes Security
  • 33. First C# Program using System; namespace Test { class ExampleClass { static void Main() { System.Console.WriteLine("Hello, world!"); } } }
  • 34. Constructions of Note  using  like import in Java: bring in namespaces  namespace  disambiguation of names  like Internet hierarchical names and C++ naming  class  like in C++ or Java  single inheritance up to object
  • 35. Constructions of Note  static void Main()  Defines the entry point for an assembly.  Four different overloads – taking string arguments and returning int’s.  Console.Write(Line)  Takes a formatted string: “Composite Format”  Indexed elements: e.g., {0}  can be used multiple times  only evaluated once  {index [,alignment][:formatting]}