SlideShare une entreprise Scribd logo
1  sur  41
Introduction to C#  Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation
C# – The Big Ideas ,[object Object],[object Object],[object Object],[object Object]
C# – The Big Ideas A component oriented language ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C# – The Big Ideas Everything really is an object ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C# – The Big Ideas Robust and durable software ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C# – The Big Ideas Preservation of Investment ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Hello World using System; class Hello { static void Main() { Console.WriteLine("Hello world"); } }
C# Program Structure ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
C# Program 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; } } }
Type System ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],int i = 123; string s = "Hello world"; 123 i s "Hello world"
Type System ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Predefined Types ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Classes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Structs ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Classes And Structs class CPoint { int x, y; ... } struct SPoint { int x, y; ... } CPoint cp = new CPoint(10, 20); SPoint sp = new SPoint(10, 20); 10 20 sp cp 10 20 CPoint
Interfaces ,[object Object],[object Object],[object Object],interface IDataBound { void Bind(IDataBinder binder); } class EditBox: Control, IDataBound { void IDataBound.Bind(IDataBinder binder) {...} }
Enums ,[object Object],[object Object],[object Object],[object Object],[object Object],enum Color: byte { Red  = 1, Green = 2, Blue  = 4, Black = 0, White = Red | Green | Blue, }
Delegates ,[object Object],[object Object],[object Object],[object Object],[object Object],delegate void MouseEvent(int x, int y); delegate double Func(double x); Func func = new Func(Math.Sin); double x = func(1.0);
Unified Type System ,[object Object],[object Object],[object Object],Stream MemoryStream FileStream Hashtable double int object
Unified Type System ,[object Object],[object Object],[object Object],[object Object],int i = 123; object o = i; int j = (int)o; 123 i o 123 System.Int32 123 j
Unified Type System ,[object Object],[object Object],[object Object],[object Object],[object Object],string s = string.Format( "Your total was {0} on {1}", total, date); Hashtable t = new Hashtable(); t.Add(0, "zero"); t.Add(1, "one"); t.Add(2, "two");
Component Development ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Properties ,[object Object],[object Object],public class Button: Control { private string caption; public string Caption { get { return caption; } set { caption = value; Repaint(); } } } Button b = new Button(); b.Caption = "OK"; String s = b.Caption;
Indexers ,[object Object],[object Object],public class ListBox: Control { private string[] items; public string this[int index] { get { return items[index]; } set {   items[index] = value; Repaint(); } } } ListBox listBox = new ListBox(); listBox[0] = "hello"; Console.WriteLine(listBox[0]);
Events  Sourcing ,[object Object],[object Object],public delegate void EventHandler(object sender, EventArgs e); public class Button {   public event EventHandler Click; protected void OnClick(EventArgs e) {   if (Click != null) Click(this, e);   } }
Events  Handling ,[object Object],public class MyForm: Form { Button okButton; public MyForm() { okButton = new Button(...); okButton.Caption = "OK"; okButton.Click += new EventHandler(OkButtonClick); } void OkButtonClick(object sender, EventArgs e) { ShowMessage("You pressed the OK button"); } }
Attributes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Attributes public class OrderProcessor { [WebMethod] public void SubmitOrder(PurchaseOrder order) {...} } [XmlRoot("Order", Namespace="urn:acme.b2b-schema.v1")] public class PurchaseOrder { [XmlElement("shipTo")]  public Address ShipTo; [XmlElement("billTo")]  public Address BillTo; [XmlElement("comment")] public string Comment; [XmlElement("items")]  public Item[] Items; [XmlAttribute("date")]  public DateTime OrderDate; } public class Address {...} public class Item {...}
Attributes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
XML Comments class XmlElement { /// <summary> ///  Returns the attribute with the given name and ///  namespace</summary> /// <param name=&quot;name&quot;> ///  The name of the attribute</param> /// <param name=&quot;ns&quot;> ///  The namespace of the attribute, or null if ///  the attribute has no namespace</param> /// <return> ///  The attribute value, or null if the attribute ///  does not exist</return> /// <seealso cref=&quot;GetAttr(string)&quot;/> /// public string GetAttr(string name, string ns) { ... } }
Statements And Expressions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],void Foo() { i == 1;  // error }
foreach Statement ,[object Object],[object Object],foreach (Customer c in customers.OrderBy(&quot;name&quot;)) { if (c.Orders.Count != 0) { ... } } public static void Main(string[] args) { foreach (string s in args) Console.WriteLine(s); }
Parameter Arrays ,[object Object],[object Object],void printf(string fmt, params object[] args) { foreach (object x in args) { ... } } printf(&quot;%s %i %i&quot;, str, int1, int2); object[] args = new object[3]; args[0] = str; args[1] = int1; Args[2] = int2; printf(&quot;%s %i %i&quot;, args);
Operator Overloading ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Operator Overloading public struct DBInt { public static readonly DBInt Null = new DBInt();   private int value; private bool defined; public bool IsNull { get { return !defined; } } public static DBInt operator +(DBInt x, DBInt y) {...} public static implicit operator DBInt(int x) {...} public static explicit operator int(DBInt x) {...} } DBInt x = 123; DBInt y = DBInt.Null; DBInt z = x + y;
Versioning ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Versioning class Derived: Base // version 1 { public virtual void Foo() { Console.WriteLine(&quot;Derived.Foo&quot;);  } } class Derived: Base // version 2a { new public virtual void Foo() { Console.WriteLine(&quot;Derived.Foo&quot;);  } } class Derived: Base // version 2b { public override void Foo() { base.Foo(); Console.WriteLine(&quot;Derived.Foo&quot;);  } } class Base // version 1 { } class Base  // version 2  { public virtual void Foo() { Console.WriteLine(&quot;Base.Foo&quot;);  } }
Conditional Compilation ,[object Object],[object Object],[object Object],[object Object],public class Debug { [Conditional(&quot;Debug&quot;)] public static void Assert(bool cond, String s) { if (!cond) { throw new AssertionException(s); } } }
Unsafe Code ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],unsafe void Foo() { char* buf = stackalloc char[256]; for (char* p = buf; p < buf + 256; p++) *p = 0; ... }
Unsafe Code class FileStream: Stream { int handle; public unsafe int Read(byte[] buffer, int index, int count) { int n = 0; fixed (byte* p = buffer) { ReadFile(handle, p + index, count, &n, null); } return n; } [dllimport(&quot;kernel32&quot;, SetLastError=true)] static extern unsafe bool ReadFile(int hFile, void* lpBuffer, int nBytesToRead, int* nBytesRead, Overlapped* lpOverlapped); }
More Information ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Contenu connexe

Tendances

C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language ComparisonRobert Bachmann
 
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITKAdvanced CPP Lecture 1- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITKPankaj Prateek
 
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITKAdvanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITKPankaj Prateek
 
3.3 programming fundamentals
3.3 programming fundamentals3.3 programming fundamentals
3.3 programming fundamentalsSayed Ahmed
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code SmellsMario Sangiorgio
 
Object oriented programming in C++
Object oriented programming in C++Object oriented programming in C++
Object oriented programming in C++jehan1987
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and OperatorsSunil OS
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)jeffz
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1Vineeta Garg
 

Tendances (14)

C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language Comparison
 
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITKAdvanced CPP Lecture 1- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 1- Summer School 2014 - ACA CSE IITK
 
C#ppt
C#pptC#ppt
C#ppt
 
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITKAdvanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
 
3.3 programming fundamentals
3.3 programming fundamentals3.3 programming fundamentals
3.3 programming fundamentals
 
Clean code
Clean codeClean code
Clean code
 
Functional Programming with C#
Functional Programming with C#Functional Programming with C#
Functional Programming with C#
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Object oriented programming in C++
Object oriented programming in C++Object oriented programming in C++
Object oriented programming in C++
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
 

En vedette

Wishnet - Prologic First - Frontoffice System
Wishnet - Prologic First - Frontoffice SystemWishnet - Prologic First - Frontoffice System
Wishnet - Prologic First - Frontoffice SystemVipinder Panchal
 
Online Hotel Management
Online Hotel ManagementOnline Hotel Management
Online Hotel ManagementSouvik Banik
 
Hotel management system project
Hotel management system projectHotel management system project
Hotel management system projectMohammed Al Babeli
 
online hotel management system
online hotel management system online hotel management system
online hotel management system ANSHUL GUPTA
 
Online Hotel Management System
Online Hotel Management SystemOnline Hotel Management System
Online Hotel Management SystemSanu Subham
 
Hotel+management+system
Hotel+management+systemHotel+management+system
Hotel+management+systemsonikaushal
 
PPT for Hotel Management System
PPT for Hotel Management SystemPPT for Hotel Management System
PPT for Hotel Management SystemCharitha Gamage
 
PPT FOR ONLINE HOTEL MANAGEMENT
PPT FOR ONLINE HOTEL MANAGEMENTPPT FOR ONLINE HOTEL MANAGEMENT
PPT FOR ONLINE HOTEL MANAGEMENTJaya0006
 
Hotel Reservation System Project
Hotel Reservation System ProjectHotel Reservation System Project
Hotel Reservation System Projectraj_qn3
 
RAVI RANA HOTEL MANAGEMENT PPT
RAVI RANA HOTEL MANAGEMENT PPTRAVI RANA HOTEL MANAGEMENT PPT
RAVI RANA HOTEL MANAGEMENT PPTSameer Gurjar
 
Project Proposal document for Hotel Management System
Project Proposal document for Hotel Management SystemProject Proposal document for Hotel Management System
Project Proposal document for Hotel Management SystemCharitha Gamage
 
Hotel management or reservation system document
Hotel management or reservation system document Hotel management or reservation system document
Hotel management or reservation system document prabhat kumar
 

En vedette (14)

Wishnet - Prologic First - Frontoffice System
Wishnet - Prologic First - Frontoffice SystemWishnet - Prologic First - Frontoffice System
Wishnet - Prologic First - Frontoffice System
 
Online Hotel Management
Online Hotel ManagementOnline Hotel Management
Online Hotel Management
 
Hotel management system project
Hotel management system projectHotel management system project
Hotel management system project
 
online hotel management system
online hotel management system online hotel management system
online hotel management system
 
Online Hotel Management System
Online Hotel Management SystemOnline Hotel Management System
Online Hotel Management System
 
Hotel+management+system
Hotel+management+systemHotel+management+system
Hotel+management+system
 
Dfd Case1
Dfd Case1Dfd Case1
Dfd Case1
 
Hotel Management System
Hotel Management SystemHotel Management System
Hotel Management System
 
PPT for Hotel Management System
PPT for Hotel Management SystemPPT for Hotel Management System
PPT for Hotel Management System
 
PPT FOR ONLINE HOTEL MANAGEMENT
PPT FOR ONLINE HOTEL MANAGEMENTPPT FOR ONLINE HOTEL MANAGEMENT
PPT FOR ONLINE HOTEL MANAGEMENT
 
Hotel Reservation System Project
Hotel Reservation System ProjectHotel Reservation System Project
Hotel Reservation System Project
 
RAVI RANA HOTEL MANAGEMENT PPT
RAVI RANA HOTEL MANAGEMENT PPTRAVI RANA HOTEL MANAGEMENT PPT
RAVI RANA HOTEL MANAGEMENT PPT
 
Project Proposal document for Hotel Management System
Project Proposal document for Hotel Management SystemProject Proposal document for Hotel Management System
Project Proposal document for Hotel Management System
 
Hotel management or reservation system document
Hotel management or reservation system document Hotel management or reservation system document
Hotel management or reservation system document
 

Similaire à Introduction to CSharp

Introduction to-csharp
Introduction to-csharpIntroduction to-csharp
Introduction to-csharpSDFG5
 
Introduction to Csharp (C-Sharp) is a programming language developed by Micro...
Introduction to Csharp (C-Sharp) is a programming language developed by Micro...Introduction to Csharp (C-Sharp) is a programming language developed by Micro...
Introduction to Csharp (C-Sharp) is a programming language developed by Micro...NALESVPMEngg
 
Introduction-to-Csharp.ppt
Introduction-to-Csharp.pptIntroduction-to-Csharp.ppt
Introduction-to-Csharp.pptAlmamoon
 
Introduction-to-Csharp.ppt
Introduction-to-Csharp.pptIntroduction-to-Csharp.ppt
Introduction-to-Csharp.pptmothertheressa
 
IntroToCSharpcode.ppt
IntroToCSharpcode.pptIntroToCSharpcode.ppt
IntroToCSharpcode.pptpsundarau
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#singhadarsh
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharpvoegtu
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharpvoegtu
 
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptxPERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptxTriSandhikaJaya
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003R696
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?Kevin Pilch
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Juan Pablo
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaJevgeni Kabanov
 
Attributes & .NET components
Attributes & .NET componentsAttributes & .NET components
Attributes & .NET componentsBình Trọng Án
 
Simulation Tool - Plugin Development
Simulation Tool - Plugin DevelopmentSimulation Tool - Plugin Development
Simulation Tool - Plugin DevelopmentFrank Bergmann
 

Similaire à Introduction to CSharp (20)

Introduction to-csharp
Introduction to-csharpIntroduction to-csharp
Introduction to-csharp
 
Introduction to Csharp (C-Sharp) is a programming language developed by Micro...
Introduction to Csharp (C-Sharp) is a programming language developed by Micro...Introduction to Csharp (C-Sharp) is a programming language developed by Micro...
Introduction to Csharp (C-Sharp) is a programming language developed by Micro...
 
Introduction-to-Csharp.ppt
Introduction-to-Csharp.pptIntroduction-to-Csharp.ppt
Introduction-to-Csharp.ppt
 
Introduction-to-Csharp.ppt
Introduction-to-Csharp.pptIntroduction-to-Csharp.ppt
Introduction-to-Csharp.ppt
 
IntroToCSharpcode.ppt
IntroToCSharpcode.pptIntroToCSharpcode.ppt
IntroToCSharpcode.ppt
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptxPERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
PERTEMUAN 1 - MENGENAL ENVIRONTMENT PROGRAM VISUAL C#.pptx
 
Introduction to c_sharp
Introduction to c_sharpIntroduction to c_sharp
Introduction to c_sharp
 
1204csharp
1204csharp1204csharp
1204csharp
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003
 
devLink - What's New in C# 4?
devLink - What's New in C# 4?devLink - What's New in C# 4?
devLink - What's New in C# 4?
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for Java
 
Visual Basic 6.0
Visual Basic 6.0Visual Basic 6.0
Visual Basic 6.0
 
Attributes & .NET components
Attributes & .NET componentsAttributes & .NET components
Attributes & .NET components
 
Simulation Tool - Plugin Development
Simulation Tool - Plugin DevelopmentSimulation Tool - Plugin Development
Simulation Tool - Plugin Development
 
C++ theory
C++ theoryC++ theory
C++ theory
 

Introduction to CSharp

  • 1. Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. Hello World using System; class Hello { static void Main() { Console.WriteLine(&quot;Hello world&quot;); } }
  • 8.
  • 9. C# Program 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; } } }
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15. Classes And Structs class CPoint { int x, y; ... } struct SPoint { int x, y; ... } CPoint cp = new CPoint(10, 20); SPoint sp = new SPoint(10, 20); 10 20 sp cp 10 20 CPoint
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28. Attributes public class OrderProcessor { [WebMethod] public void SubmitOrder(PurchaseOrder order) {...} } [XmlRoot(&quot;Order&quot;, Namespace=&quot;urn:acme.b2b-schema.v1&quot;)] public class PurchaseOrder { [XmlElement(&quot;shipTo&quot;)] public Address ShipTo; [XmlElement(&quot;billTo&quot;)] public Address BillTo; [XmlElement(&quot;comment&quot;)] public string Comment; [XmlElement(&quot;items&quot;)] public Item[] Items; [XmlAttribute(&quot;date&quot;)] public DateTime OrderDate; } public class Address {...} public class Item {...}
  • 29.
  • 30. XML Comments class XmlElement { /// <summary> /// Returns the attribute with the given name and /// namespace</summary> /// <param name=&quot;name&quot;> /// The name of the attribute</param> /// <param name=&quot;ns&quot;> /// The namespace of the attribute, or null if /// the attribute has no namespace</param> /// <return> /// The attribute value, or null if the attribute /// does not exist</return> /// <seealso cref=&quot;GetAttr(string)&quot;/> /// public string GetAttr(string name, string ns) { ... } }
  • 31.
  • 32.
  • 33.
  • 34.
  • 35. Operator Overloading public struct DBInt { public static readonly DBInt Null = new DBInt(); private int value; private bool defined; public bool IsNull { get { return !defined; } } public static DBInt operator +(DBInt x, DBInt y) {...} public static implicit operator DBInt(int x) {...} public static explicit operator int(DBInt x) {...} } DBInt x = 123; DBInt y = DBInt.Null; DBInt z = x + y;
  • 36.
  • 37. Versioning class Derived: Base // version 1 { public virtual void Foo() { Console.WriteLine(&quot;Derived.Foo&quot;); } } class Derived: Base // version 2a { new public virtual void Foo() { Console.WriteLine(&quot;Derived.Foo&quot;); } } class Derived: Base // version 2b { public override void Foo() { base.Foo(); Console.WriteLine(&quot;Derived.Foo&quot;); } } class Base // version 1 { } class Base // version 2 { public virtual void Foo() { Console.WriteLine(&quot;Base.Foo&quot;); } }
  • 38.
  • 39.
  • 40. Unsafe Code class FileStream: Stream { int handle; public unsafe int Read(byte[] buffer, int index, int count) { int n = 0; fixed (byte* p = buffer) { ReadFile(handle, p + index, count, &n, null); } return n; } [dllimport(&quot;kernel32&quot;, SetLastError=true)] static extern unsafe bool ReadFile(int hFile, void* lpBuffer, int nBytesToRead, int* nBytesRead, Overlapped* lpOverlapped); }
  • 41.