SlideShare une entreprise Scribd logo
1  sur  139
C# in Detail Jon Jagger Software Trainer, Designer, Consultant www.jaggersoft.com jon @   jaggersoft.com { JSL } Part 2
Blatant Advert ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],C# in Detail is also available as an instructor led course
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
string C# Programming Fundamentals Objects Relationships Systems
string Type ,[object Object],[object Object],[object Object],s stack heap null @ t static void  Main() { string  s =  null ; string  t =  "Hiker" ; ... t[0] =  'B' ; } Hiker compile  time error
indexer ,[object Object],[object Object],[object Object],static void  Func( string  s) { for  ( int  i = 0; i != s.Length; i++)  { char  c = s[i]; Console.Write(c); } }
System.String ,[object Object],namespace  System { public sealed class  String ... {  ... // static methods public static int  Compare( string ,  string ); public static bool  Equals( string ,  string ); public static  string  Format( string ,  params object []); ... // readonly property public int  Length {  get;  } // readonly indexer  public char this  [ int  index] {  get;  } // instance methods public int  CompareTo( string ); public override bool  Equals( object ); public new bool  Equals( string ); ... } }
StringBuilder ,[object Object],namespace  System.Text { public sealed class  StringBuilder  {  public  StringBuilder(); // read-write properties public int  Length  {  get ;  set ; } public int  Capacity {  get ;  set ; } // read-write indexer  public char this  [ int  index] {  get ;  set ; } // instance methods public  StringBuilder Append(...); public  StringBuilder Insert(...); public  StringBuilder Remove( int ,  int ); public  StringBuilder Replace(...); ... public override string  ToString(); } }
string Literals ,[object Object],[object Object],[object Object],[object Object],"c:emp" @"c:emp" @"quote"" char" @" MP: we got a slug JC: does it talk? MP: yup JC: I'll have it" c:  emp c:emp quote"char MP: we got a slug JC: does it talk? MP: yup JC: I'll have it
string Operators ,[object Object],[object Object],[object Object],[object Object],[object Object],IsTrue(s == t); IsTrue(s.Equals(t)); IsFalse(( object )s == ( object )t); s stack heap @ @ t Hiker Hiker IsTrue(s == t); IsTrue(s.Equals(t)); IsTrue(( object )s == ( object )t); s @ @ t Hiker
class C# Programming Fundamentals Objects Relationships Systems
class Declaration ,[object Object],class  Pair {  public int  X, Y; }; optional semi-colon by convention public names start with an uppercase letter (PascalCasing) class  Pair {  private int  x, y; } ...and private names  start with a lowercase letter (camelCasing) class  Pair {  int  x, y; } default access is  private
object Creation ,[object Object],[object Object],[object Object],p stack ? .X .Y heap required static void  Main() { Pair p; } static void  Main() { Pair p =  null ; } static void  Main() { Pair p =  new  Pair(); } p null p @ 0 0
class Constructor ,[object Object],[object Object],[object Object],[object Object],class  Pair { } you declare a default c'tor class  Pair { public  Pair( int  x,  int  y) {...}  } compiler  declares a default c'tor class  Pair { public  Pair() { ... } } no one declares a default c'tor
: this(...) ,[object Object],[object Object],[object Object],class  Point { public  Point( int  x,  int  y)  :  this (x, y, Colour.Red) {  } public  Point( int  x,  int  y, Colour c)  {  ... }  ... private int  x, y; private  Colour c; }
instance Fields ,[object Object],[object Object],[object Object],[object Object],class  Point { public  Point( int  x,  int  y)  {  this .x = x; y = y; }  ... private int  x; private int  y = 42; } no warning! OK OK OK
readonly Fields ,[object Object],[object Object],compile time errors class  Pair { public  Pair( int  x,  int  y)  {  this .x = x; this .y = y; } public void  Reset() { x = 0; y = 0; } private readonly int  x, y; } this declares Pair as  an immutable  object
const Fields ,[object Object],[object Object],[object Object],class  Pair { private const int  x = 0, y = 0; } class  BadFields { ... BadFields(...) { question = 9 * 6; } ...  static const int  answer = 42; ...  const int  question; ...  const  Pair origin =  new  Pair(); } OK compile time errors this declares Pair with no instance fields
static Fields ,[object Object],[object Object],[object Object],[object Object],[object Object],class  Pair { ...  static  Pair origin; ...  static  Pair topLeft =  new  Pair(10,20); ...  static  AnyClass field; ...  static string  both = "Arthur"; } Pair p =  new  Pair(); ... F(p.Origin);  // compile-time error F(Pair.Origin);  // OK
static Constructor ,[object Object],[object Object],[object Object],[object Object],class  GoodExample { static  GoodExample() { origin =  new  Pair(0,0); } ...static readonly  Pair origin; } OK class  BadExample { public   static  GoodExample() { x = 42; } ...const int  x; } compile time errors
Copy Parameters ,[object Object],[object Object],[object Object],[object Object],static void  Method(Pair parameter) { parameter =  new  Pair(42,42); } static void  Main() { Pair arg =  new  Pair(0,0); Console.WriteLine(arg.X); Method(arg); Console.WriteLine(arg.X); } 0 0
ref Parameters ,[object Object],[object Object],[object Object],[object Object],[object Object],static void  Method( ref  Pair parameter) { parameter =  new  Pair(42,42); } static void  Main() { Pair arg =  null ; //Console.WriteLine(p.X); Method( ref  arg); Console.WriteLine(arg.X); } 42 Method(  ref  type [ ] array ) allowed
out Parameters ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],static void  Method( out  Pair parameter) { parameter =  new  Pair(42,42); } static void  Main() { Pair arg;  //Console.WriteLine(p.X); Method( out  arg); Console.WriteLine(arg.X); } 42 Method(  out  type [ ] array ) allowed
in Parameters? ,[object Object],[object Object],[object Object],argument parameter optional required Copy ref out @ @ @ @  @@ @@ 0 0 initialize
[ ] Arrays C# Programming Fundamentals Objects Relationships Systems
Array Variables ,[object Object],[object Object],int [] row =  null ; int [,] grid =  null ; int [,,] threeD =  null ; row stack heap null null grid
Array Instances ,[object Object],[object Object],[object Object],int [] row =  new int [4]; int [,] grid =  new int [2,3]; row stack heap @ @ grid 0 0 0 0 0 0 0 0 0 0 array of  struct s
Array Initialisation ,[object Object],[object Object],[object Object],[object Object],int [] row =  new int [4] {1,2,3,4}; int [,] grid =  new int [,] { {1,2,3}, {4,5,6,}, }; int [,] shortcut = { {1,2,3}, {4,5,6} }; row stack heap @ @ grid 1 2 3 4 1 2 3 4 5 6 trailing commas are permitted
System.Array ,[object Object],namespace  System { public class  Array  {  protected  Array(); ... // readonly properties public int  Length { get; } public int  Rank  { get; } // instance methods public int  GetLength( int ); // static methods public static void  Clear(Array,  int ,  int ); ... } } int [,] cosmic = { {1,2,3}, {4,5,6} }; Console.Write(cosmic.Length); Console.Write(cosmic.Rank); Console.Write(cosmic.GetLength(0)); Console.Write(cosmic.GetLength(1)); 6223
Using Arrays ,[object Object],[object Object],class  Example { static void  Use( int [,] grid) {  int  rowLength = grid.GetLength(0); int  colLength = grid.GetLength(1); for (int  row = 0; row != rowLength; row++)  { for (int  col = 0; col != colLength; col++)  { Console.WriteLine(grid[row,col]); } } } static void  Main() {  Use( new int [,]{ {1,2,3}, {4,5,6} }); ... } } there is no direct way to make rowLength constant
Ragged Arrays ,[object Object],[object Object],[object Object],int [][] ragged =  new int [3][ ]; int [][][] tatters =  null ; ragged stack heap @ null null null tatters null
Ragged Initialisation ,[object Object],[object Object],int [][] ragged =  new int [3][4]; int [][] ragged =  new int [3][]  { new int [2], null , new int [4]{ 1, 2, 3, 4 }  }; ragged stack heap @ @ null @ 0 0 1 2 3 4 { ... }  shorthand allowed  here but not  here compile time error
params type[ ] ,[object Object],[object Object],[object Object],static void  GreyHole( params   int [] row) { if  (row !=  null ) Console.WriteLine(row.Length); else Console.WriteLine( "null" ); } static void  Main() { GreyHole( null ); GreyHole(); GreyHole(1); GreyHole( new int []{1, 2}); GreyHole(1,2,3); } null 0 1 2 3 params  is not part of the signature
params object[ ] ,[object Object],[object Object],[object Object],static void  BlackHole( params   object [] row) { if  (row !=  null ) Console.WriteLine(row.Length); else Console.WriteLine( "null" ); } static void  Main() { BlackHole( null ); BlackHole(); BlackHole(1M); BlackHole( new int []{1,2}); BlackHole(1, 2.0,  "three" ); } null 0 1 1 3
Array Notes int [ ] illegal[ , ]; class  Base {...} class  Derived : Base {...} Derived[] ds =  new  Derived[]{...}; Base[] bs = ds; unsafe  { int  * array =  stackalloc int [42]; ... } only one syntax C# supports array covariance you can create an array on the stack, but only in  unsafe  code object  o =  new int [42]; arrays are reference types int [ ][ , ] mixed; you can mix the two kinds of arrays
Boxing C# Programming Fundamentals Objects Relationships Systems
Recap ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],object value enum class interface [ ]array delegate struct value object object object @ @ @ @
struct vs class struct  Pair  {  int  x, y; ... } Pair p =  new  Pair(1,2); Pair copy = p; p.x stack heap class  Pair  {  int  x, y; ... } Pair p =  new  Pair(1,2); Pair copy = p; 1 2 @ p @ copy 1 2 p.y copy.x copy.y .x 1 2 .y
Objects Everywhere ,[object Object],[object Object],[object Object],System.Int32 « struct » System.ValueType « class » System.Enum « class » Suit « enum » Pair « struct » System.Object « class » int  == System.Int32
Problem? ,[object Object],[object Object],[object Object],struct  Pair  {  public int  X, Y; ... } class  Example { static object  Dangle() { Pair p =  new  Pair(1,2); object  o = p; return  o; } static void  Main() { object  o = Dangle(); ... } } p.X stack 1 2 @ o p.Y ?
Boxed Solution ,[object Object],[object Object],[object Object],[object Object],the copy is the same plain bitwise copy  used for value parameters/returns struct  Pair  {  public int  X, Y; ... } static void  Function() { Pair p =  new  Pair(1,2); object  o = p; } p.X stack heap 1 2 p.Y .X 1 2 .Y @ o box
Unboxing ,[object Object],[object Object],[object Object],struct  Pair  {  public int  X, Y; ... } static void  Function() { Pair p =  new  Pair(1,2); object  o = p; p.X = p.Y = 0; Pair q = (Pair)o; } p.X stack heap 0 0 p.Y .X 1 2 .Y @ o cast q.X 1 2 q.Y box unbox
System.Object ,[object Object],namespace  System { public class  Object  {  public  Object(); public virtual bool   Equals( object ); public virtual int   GetHashCode(); public  Type  GetType(); public virtual string  ToString(); ... } } static void  AnySingleArgument( object  accepted) { ... } any value variable (implicit boxing) any reference variable (implicit conversion)
No Overhead ,[object Object],[object Object],[object Object],[object Object],[object Object],Pair «  struct  » Object «  class  » Pair Reference «  class  » Int32 Reference «  class  » Int32 «  struct  » 42.ToString() is  not  a  virtual  call 1 1
Inheritance C# Programming Fundamentals Objects Relationships Systems
Extension ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],ViolinPlayer «  class  » Musician «  class  » class  Musician { public void  NotVirtual()... } class  ViolinPlayer : Musician { ... }
: base(...) ,[object Object],[object Object],[object Object],[object Object],class  Musician { public  Musician( string  name)... public void  NotVirtual()... } class  ViolinPlayer : Musician { public  ViolinPlayer( string  name) :  base (name) { ... } }
Method Access ,[object Object],[object Object],[object Object],class  GoodClass { public   virtual  void Alpha()... protected   virtual  void Beta()... private   void Gamma()... } class  BadClass { private virtual void  Delta()... } struct  GoodStruct { public  void  Alpha()... private void  Gamma()... } struct  BadStruct { protected void  Beta()... }
virtual  Methods ,[object Object],[object Object],[object Object],class  Musician { ... public virtual void  TuneUp() { ... } } class  ViolinPlayer : Musician { public virtual void  TuneUp() { ... } } this does  not override TuneUp from the Musician class
override  Methods ,[object Object],[object Object],[object Object],[object Object],class  Musician { ... public virtual void  TuneUp() { ... } } class  ViolinPlayer : Musician { public override void  TuneUp() { ... } } this does same access too
sealed  Methods ,[object Object],[object Object],[object Object],[object Object],class  Musician { ... public virtual void  TuneUp() { ... } } class  ViolinPlayer : Musician { public sealed override void  TuneUp() { ... } } sealed  is always used with  override
new Methods ,[object Object],[object Object],[object Object],[object Object],class  Musician { ... public virtual void  TuneUp() { ... } } class  ViolinPlayer : Musician { public new virtual void  TuneUp() { ... } }
Table ,[object Object],struct class override no* yes sealed no yes new no* yes public yes yes protected no yes private yes yes virtual no yes only needed when overriding or hiding methods from System.ValueType
Interfaces C# Programming Fundamentals Objects Relationships Systems
interface ,[object Object],[object Object],[object Object],interface names  should start with an I interface  ITuneable { void  TuneUp(); } interface  IPluckable { void  Pluck(); } IPluckable «  interface  » ITuneable «  interface  »
Multiple Interfaces ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],class  Violin  : Instrument , IPluckable , ITuneable { ... } IPluckable «  interface  » ITuneable «  interface  » Violin «  class  » Instrument «  class  »
I.I.I. ,[object Object],[object Object],[object Object],a class must implement all inherited interface methods interface  ITuneable { void  TuneUp(); } interface  IPluckable { void  Pluck(); } class  Violin : IPluckable, ITuneable { public  void  TuneUp() { ... } public virtual void  Pluck() { ... } ... }
E.I.I. ,[object Object],[object Object],[object Object],interface  ITuneable { void  TuneUp(); } interface  IPluckable { void  Pluck(); } class  Violin : Instrument , IPluckable, ITuneable { void  ITuneable.TuneUp() { ... } void  IPluckable.Pluck() { ... } ... } consider inheriting two operations with the same  signature you can mix III and EII
interface Property ,[object Object],[object Object],interface  IButton { string  Caption {  get ;  set ; } ... } class  Button : IButton { public virtual string  Caption { get  { ... } set  { ... }  } ... private string  caption; }
interface Indexer ,[object Object],[object Object],[object Object],interface  IDictionary { string   this  [  string  word ] {  get ;  set ; } ... } class  Dictionary : IDictionary { public virtual string this  [  string  word ] { get  { ... } set  { ... }  } ... }
is ,[object Object],[object Object],[object Object],static void  GreyHole( object  o) { if  (o  is  IPluckable) { IPluckable ip = (IPluckable)o; ip.Pluck() ... } } static void  Main() { GreyHole( new  Violin()); GreyHole(42); } check once check twice cast
as ,[object Object],[object Object],[object Object],static void  GreyHole( object  o) { IPluckable ip = o  as  IPluckable; if  (ip !=  null ) { ip.Pluck(); ... } } static void  Main() { GreyHole( new  Violin()); GreyHole(42); } check once
typeof ,[object Object],[object Object],[object Object],[object Object],static void  Main() { Violin stradi =  new  Violin(); IPluckable ip = stradi; Type t1 = ip.GetType(); Type t2 =  typeof (Violin); Type t3 = Type.GetType( "Violin" ); Console.WriteLine(t1 == t2); Console.WriteLine(t2 == t3); Console.WriteLine(( object )t1 == ( object )t2); Console.WriteLine(( object )t2 == ( object )t3); } True True True True
ref out ,[object Object],[object Object],[object Object],interface  IPluckable { void  Pluck(); } static void  Replace( ref  IPluckable instrument) { instrument =  new  Guitar(); } static void  Create( out  IPluckable instrument) { instrument =  new  Banjo(); }
Table ,[object Object],struct class override no* yes sealed no yes new no* yes public yes yes protected no yes private yes yes virtual no yes i'face no no yes no no no no
Abstract Classes C# Programming Fundamentals Objects Relationships Systems
abstract Classes ,[object Object],[object Object],[object Object],[object Object],abstract class  Bar { ... private int  instanceMethod() { ... } private int  instanceField; } abstract class  Foo : Bar { ... public static int  StaticMethod() { ... } public static int  StaticField; }
abstract Methods ,[object Object],[object Object],[object Object],[object Object],abstract class  Foo : Bar { public abstract void  Method(); ... }
abstract Notes ,[object Object],[object Object],[object Object],abstract class  Bar { protected virtual void  Method()  {  ...  } ... } abstract class  Foo : Bar { protected abstract override void  Method(); ... }
sealed Classes ,[object Object],[object Object],[object Object],[object Object],[object Object],abstract class  Foo : Bar { protected abstract  Method(); } sealed class  Wibble : Foo { protected override void  Method()  {  ...  } ... }
Table ,[object Object],struct class override no* yes sealed no yes new no* yes public yes yes protected no yes private yes yes virtual no yes i'face no no yes no no no no abstract yes yes yes yes yes no yes sealed yes yes yes yes yes yes no abstract no no no yes no
Another Table ,[object Object],override new sealed virtual 1 2 N N abstract • abstract N 3 N • virtual • N 4 override • N new • sealed modifier  order is not significant
Exceptions C# Programming Fundamentals Objects Relationships Systems
System.Exception ,[object Object],namespace  System { public class  Exception ... {  public  Exception(); public  Exception( string ); public  Exception( string , Exception); ... public  Exception InnerException  {  get ; } public virtual string  Message {  get ; } public virtual string  StackTrace  {  get ; } ... public override string  ToString(); ... } }
Hierarchy Exception ArithmeticException InvalidCastException DivideByZeroException OutOfMemoryException NullReferenceException OverflowException SystemException ... ExecutionEngineException IndexOutOfRangeException
throw ,[object Object],[object Object],class  Matrix  {  public  Matrix( int  rowSize,  int  colSize) { ... } public  Row  this  [  int  index ] {  get  { BoundsCheck(index); ... } set  { BoundsCheck(index); ... } } // validation private void  BoundsCheck( int  index) { if  (index < 0 || index >= rows.Length) throw new  IndexOutOfRangeException(); } // representation private  Row[] rows; } don't forget the  new
try catch ,[object Object],[object Object],[object Object],try  {  FileInfo source =  new  FileInfo(filename); int  length = ( int )source.Length; char [] contents =  new   char [length]; ... } catch  (SecurityException caught) { ...  } catch  (IOException caught) { ...  } catch  (OutOfMemoryException) { ...  } catch  { ...  throw ;  } name is optional general catch block
finally ,[object Object],[object Object],[object Object],[object Object],TextReader reader =  null ; try  {  FileInfo source =  new  FileInfo(filename); int  length = ( int )source.Length; char [] contents =  new   char [length]; reader = source.OpenText(); reader.Read(contents, 0, length); ... } ... finally  { if  (reader !=  null ) { reader.Close(); }  } definite assignment rules, OK
Local Resources ,[object Object],[object Object],[object Object],[object Object],TextReader reader =  null ; try  {  FileInfo source =  new  FileInfo(filename); int  length = ( int )source.Length; char [] contents =  new   char [length]; reader = source.OpenText(); reader.Read(contents, 0, length); ... } ... finally  { if  (reader !=  null ) { reader.Close(); }  }
using Statements ,[object Object],[object Object],[object Object],[object Object],using  ( type variable  =  init)   embedded - statement { type variable  =  init ; try  { embedded - statement } finally  { if  ( variable  !=  null ) { ((IDisposable) variable ).Dispose(); } } } precisely equivalent to
IDisposable struct  AutoClosing : IDisposable { public  AutoClosing(TextReader reader) { if  (reader ==  null )  { throw new  ArgumentNullException(); } target = reader; } public void  Dispose() {  target.Close(); } private readonly  TextReader target; } interface  IDisposable { void  Dispose(); }
Preference? ... TextReader reader = source.OpenText(); using  ( new  AutoClosing(reader)) { reader.Read(contents, 0, length); ... } TextReader reader =  null ; try  {  ... reader = source.OpenText(); reader.Read(contents, 0, length); ... } finally  { if  (reader !=  null ) { reader.Close(); }  } Before... ...After
lock ,[object Object],[object Object],public class  Monitor { public static void  Enter( object ); public static void  Exit( object ); ... } lock  ( expression ) e mbedded - statement System.Threading.Monitor.Enter( expression ); try  { embedded - statement } finally  { System.Threading.Monitor.Exit( expression ) ; } precisely equivalent to ( expression  is evaluated once)
Exception Notes ,[object Object],[object Object],[object Object]
Garbage Collection C# Programming Fundamentals Objects Relationships Systems
The Miracle of Birth ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Get that would you, Deidre....
Death ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Shall we take our cars?
Finalize ,[object Object],[object Object],[object Object],[object Object],[object Object],public class  Resource  {  ... public void  Dispose() { this .Finalize(); } protected override void  Finalize() { ... } } compile  time  errors
Destructor ,[object Object],[object Object],[object Object],[object Object],[object Object],public class  Resource  {  ... ~Resource() { //...   } ... } public class  Resource  {  ... protected override void  Finalize() { //...  base .Finalize(); } ... }
GC Notes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Nested Types C# Programming Fundamentals Objects Relationships Systems
Nested Types ,[object Object],[object Object],[object Object],class  Outer { interface  Space  { }   abstract class  Reaches  { } class  Limits  { } sealed class   Hebrides { } struct   Mongolia { } } internal   access private   access
Nested Access ,[object Object],[object Object],[object Object],[object Object],class  Outer { public class  Inner  {  private void  peek(Outer can) { can.peek( this ); } } private void  peek(Inner cannot)  {  cannot.peek( this ); } } OK Fails Outer.peek(Inner cannot) Inner.peek(Outer can)
Access Modifiers ,[object Object],[object Object],[object Object],internal protected internal private protected Y public Y non-nested Y Y Y Y nested Y protected OR internal
Semantics ,[object Object],[object Object],[object Object],[object Object],class  Outer { ... class  Nested {  ... } ...   } Outer.Nested «  class  » Outer «  class  » Outer$Inner «  class  » Outer «  class  » Outer.this 1 C#, C++ Java
Delegates C# Programming Fundamentals Objects Relationships Systems
delegate Type ,[object Object],[object Object],[object Object],[object Object],delegate void  Func( string  s); class  Eg { public static void  ForAll( string [] args, Func call)  {  foreach  ( string  arg  in  args) { call(arg);  }  } } Func is a type name
static Method ,[object Object],[object Object],delegate void  Func( string  s); ... class  Test { static void  Display( string  s)  {  ...  } static void  Main( string [] args) { Eg.ForAll(args,  new  Func(Test.Display)); Eg.ForAll(args,  new  Func(Display)); } } note no ( ) create a delegate instance
Instance Method ,[object Object],[object Object],delegate void  Func( string  s); ... class  Test { void  Stash( string  s)  {  ...  } void  NotMain( string [] args) { Eg.ForAll(args,  new  Func( this .Stash)); Eg.ForAll(args,  new  Func(Stash)); } }
Remember This? delegate void  Method(); ... TextReader reader = source.OpenText(); using  ( new  Finally( new  Method(reader.Close))) { reader.Read(contents, 0, length); ... } TextReader reader =  null ; try  {  ... reader = source.OpenText(); reader.Read(contents, 0, length); ... } finally  { if  (reader !=  null ) { reader.Close(); }  } ...After Before...
Finally public delegate void  Method(); public struct  Finally : IDisposable { public  Finally(Method call)  { if  (call ==  null ) { throw new  ArgumentNullException(); } this .call = call; }  public override void  Dispose() { call(); } private readonly  Method call; }
Mulitcast delegate ,[object Object],[object Object],[object Object],delegate void  Pred( string  s); ... class  Test { void  DoThis( string  s) { ... } static void  ThenThat( string  s) { ... } void  Method( string  arg) { Pred call =  null ; call +=  new  Pred( this .DoThis); call +=  new  Pred(Test.ThenThat); ... call(arg); } }
delegate Notes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Events C# Programming Fundamentals Objects Relationships Systems
event Delegates ,[object Object],[object Object],[object Object],namespace  System.Windows.Forms { public class  Button : ... {  ... public event  EventHandler Click; ... ... protected void  OnClick(EventArgs e) { if  (Click !=  null )  { Click( this , e); } } ... } }
Event Delegates ,[object Object],[object Object],[object Object],namespace  System { public delegate  void  EventHandler ( object  sender,  EventArgs e ); ... public class  EventArgs { ... } }
Event Example ,[object Object],[object Object],using  System; using  System.Windows.Forms; class  MyForm : Form { private void  InitializeComponent()  {  openFile =  new  Button(); ... openFile.Click +=  new  EventHandler(OpenFile); } protected void  OpenFile( object  sender, EventArgs e)  {  ...  } private  Button openFile; } Note case difference: openFile vs OpenFile
Event Properties ,[object Object],[object Object],[object Object],[object Object],[object Object],namespace  System.Windows.Forms { public class  Button : ... {  ... public event  EventHandler Click { add  { ... } remove  { ... } } ... } }
Namespaces C# Programming Fundamentals Objects Relationships Systems
namespace ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],namespace  Accu { namespace  Conference { ... } } namespace  Informant {  ... } namespace  Accu.Conference { ... ... ... ... } namespace  Informant {  ... }
using Directive ,[object Object],[object Object],[object Object],using  System; class  Bar { ... } namespace  Accu.Conference { using  System.Collections; ... class  Foo : Bar { static void  Main(String[] args) { Console.Write(args[0]); } ... private  Hashtable store; }  }
using Alias ,[object Object],[object Object],[object Object],namespace  CSharp { using  Vector = System.Collections.ArrayList; class  SourceFile { ... Vector tokens; } }
Namespace Notes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Assemblies C# Programming Fundamentals Objects Relationships Systems
Modules ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],C:gt; csc ... /target:module ...
Assembly ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],physically  or  logically containing C:gt; csc ... /target:library ... C:gt; csc ... /addmodule:...  C:gt; csc ... /target:exe /reference:...
Deployment ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Versioning ,[object Object],[object Object],[object Object],[object Object],<major>.<minor>.<build>.<revision> incompatible maybe compatible Quick Fix Engineering
Version Policy ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],... <BindingPolicy> <BindingRedir Name=&quot;Wibble&quot; Originator=&quot;32ab4ba45e0a69a1&quot; Version=&quot;*&quot; VersionNew=&quot;6.1.1212.14&quot; UseLatestBuildRevision=&quot;no&quot;/> </BindingPolicy>
internal access ,[object Object],[object Object],[object Object],[object Object],an assembly of four classes public internal private
[Attributes] C# Programming Fundamentals Objects Relationships Systems
What Are They? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Attribute Class ,[object Object],[object Object],[object Object],... public sealed class  DeveloperAttribute : System.Attribute { ... public  DeveloperAttribute( string  name) { ... } ... }
[ tag ]  ,[object Object],[object Object],[DeveloperAttribute(&quot;Jon Jagger&quot;)] public struct  ConstInt { public  ConstInt( int  value) { this .value = value; } public static implicit operator int (ConstInt from)  {  return  from.value; }  private readonly int  value; }
Problem ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
AttributeUsage ,[object Object],[object Object],[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface)] public sealed class  DeveloperAttribute : System.Attribute { ... public  DeveloperAttribute( string  name) { ... } ... }
Multiple Tags ,[object Object],[object Object],[AttributeUsage(AttributeTargets.Class | ..., AllowMultiple =  true )] public sealed class  DeveloperAttribute : System.Attribute { ... public  DeveloperAttribute( string  name) { ... } ... } [DeveloperAttribute(&quot;Jon Jagger&quot;)] [DeveloperAttribute(&quot;Patrick Jagger&quot;)] public struct  ConstInt { ... }
Positional ,[object Object],[object Object],[object Object],... public sealed class  DeveloperAttribute : System.Attribute { public  DeveloperAttribute( string  name) { ... } ... } [DeveloperAttribute(&quot;Jon Jagger&quot;)] public struct  ConstInt { ... }
Named ,[object Object],[object Object],[object Object],[object Object],... public sealed class  DeveloperAttribute : System.Attribute { public  DeveloperAttribute( string  name) ... ... public string  TelExt  {  get  {...}  set  {...}  } } [DeveloperAttribute(&quot;Patrick Jagger&quot;)] [DeveloperAttribute(&quot;Jon Jagger&quot;, TelExt=&quot;4263&quot;)] public struct  ConstInt  { ... }
metadata ,[object Object],[object Object]
Notes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Reflection C# Programming Fundamentals Objects Relationships Systems
Terminology ,[object Object],[object Object],Reflection is the ability of a program to manipulate as data something representing the state of the program during its own execution. There are two apects to such manipulation: Introspection is the ability of a program to  observe  and therefore reason about its own state.  Intercession is the ability of a program to  modify  its own execution state or alter its own interpretation or meaning.  Both apects require a mechanism for encoding execution state as data; providing such an encoding is called reification Richard Gabriel, et al
Attributes ,[object Object],public sealed class  DeveloperAttribute ... { ... public override string  ToString() { ... } ... } public class  Example { static void  Main() { string  typename = &quot;ConstInt&quot;; Type t = Type.GetType(typename); object [] atts = t.GetCustomAttributes( true ); foreach  ( object  att in atts) { Console.WriteLine(att); } }  }
Remember This? TextReader reader = source.OpenText(); using  ( new  Finally(reader,  &quot;Close&quot; )) { reader.Read(contents, 0, length); ... } TextReader reader =  null ; try  {  ... reader = source.OpenText(); reader.Read(contents, 0, length); ... } finally  { if  (reader !=  null ) { reader.Close(); }  } ...After
Finally using  System; using  System.Reflection; public struct  Finally : IDisposable { public  Finally( object  target,  string  methodName)  { this .target = target; this .methodName = methodName; }  public void  Dispose() { Type t = target.GetType(); MethodInfo method = t.GetMethod(methodName); if  (method !=  null ) { t.InvokeMember( methodName, BindingFlags.InvokeMethod, target,  new object [0] ); } } private readonly object  target; private readonly string  methodName; }
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Standards ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Bibliography ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Contenu connexe

Tendances

Generic Programming seminar
Generic Programming seminarGeneric Programming seminar
Generic Programming seminarGautam Roy
 
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...Francesco Casalegno
 
Testing for share
Testing for share Testing for share
Testing for share Rajeev Mehta
 
What's New in C++ 11/14?
What's New in C++ 11/14?What's New in C++ 11/14?
What's New in C++ 11/14?Dina Goldshtein
 
C++11 smart pointer
C++11 smart pointerC++11 smart pointer
C++11 smart pointerLei Yu
 
C++11: Rvalue References, Move Semantics, Perfect Forwarding
C++11: Rvalue References, Move Semantics, Perfect ForwardingC++11: Rvalue References, Move Semantics, Perfect Forwarding
C++11: Rvalue References, Move Semantics, Perfect ForwardingFrancesco Casalegno
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Chris Adamson
 
Advanced C programming
Advanced C programmingAdvanced C programming
Advanced C programmingClaus Wu
 
C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language ComparisonRobert Bachmann
 

Tendances (20)

C++11
C++11C++11
C++11
 
Smart Pointers in C++
Smart Pointers in C++Smart Pointers in C++
Smart Pointers in C++
 
Generic Programming seminar
Generic Programming seminarGeneric Programming seminar
Generic Programming seminar
 
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
 
Testing for share
Testing for share Testing for share
Testing for share
 
Cheat Sheet java
Cheat Sheet javaCheat Sheet java
Cheat Sheet java
 
Antlr V3
Antlr V3Antlr V3
Antlr V3
 
What's New in C++ 11/14?
What's New in C++ 11/14?What's New in C++ 11/14?
What's New in C++ 11/14?
 
What's New in C++ 11?
What's New in C++ 11?What's New in C++ 11?
What's New in C++ 11?
 
C++11
C++11C++11
C++11
 
C++11 smart pointer
C++11 smart pointerC++11 smart pointer
C++11 smart pointer
 
C++11: Rvalue References, Move Semantics, Perfect Forwarding
C++11: Rvalue References, Move Semantics, Perfect ForwardingC++11: Rvalue References, Move Semantics, Perfect Forwarding
C++11: Rvalue References, Move Semantics, Perfect Forwarding
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
 
Advanced C programming
Advanced C programmingAdvanced C programming
Advanced C programming
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 
C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language Comparison
 
C++ 11
C++ 11C++ 11
C++ 11
 
Generic programming
Generic programmingGeneric programming
Generic programming
 
10. Recursion
10. Recursion10. Recursion
10. Recursion
 

En vedette (6)

C# Generics
C# GenericsC# Generics
C# Generics
 
Delegates and events
Delegates and events   Delegates and events
Delegates and events
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
Indexers, Partial Class And Partial Method
Indexers, Partial Class And Partial MethodIndexers, Partial Class And Partial Method
Indexers, Partial Class And Partial Method
 
Oops ppt
Oops pptOops ppt
Oops ppt
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 

Similaire à Csharp In Detail Part2

Java 5 New Feature
Java 5 New FeatureJava 5 New Feature
Java 5 New Featurexcoda
 
Can someone help me please I need help writing this code using Java.pdf
Can someone help me please I need help writing this code using Java.pdfCan someone help me please I need help writing this code using Java.pdf
Can someone help me please I need help writing this code using Java.pdfmarketing413921
 
The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type PatternsSimon Ritter
 
Programing with java for begniers .pptx
Programing with java for begniers  .pptxPrograming with java for begniers  .pptx
Programing with java for begniers .pptxadityaraj7711
 
Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)Andrew Petryk
 
Practices For Becoming A Better Programmer
Practices For Becoming A Better ProgrammerPractices For Becoming A Better Programmer
Practices For Becoming A Better ProgrammerSrikanth Shreenivas
 
New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancementRakesh Madugula
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondMario Fusco
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdfarshiartpalace
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)Tak Lee
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsHCMUTE
 
Core csharp and net quick reference
Core csharp and net quick referenceCore csharp and net quick reference
Core csharp and net quick referenceilesh raval
 

Similaire à Csharp In Detail Part2 (20)

core java
 core java core java
core java
 
Java 5 New Feature
Java 5 New FeatureJava 5 New Feature
Java 5 New Feature
 
Can someone help me please I need help writing this code using Java.pdf
Can someone help me please I need help writing this code using Java.pdfCan someone help me please I need help writing this code using Java.pdf
Can someone help me please I need help writing this code using Java.pdf
 
Computer programming 2 Lesson 12
Computer programming 2  Lesson 12Computer programming 2  Lesson 12
Computer programming 2 Lesson 12
 
The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type Patterns
 
Programing with java for begniers .pptx
Programing with java for begniers  .pptxPrograming with java for begniers  .pptx
Programing with java for begniers .pptx
 
Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)
 
Lezione03
Lezione03Lezione03
Lezione03
 
Lezione03
Lezione03Lezione03
Lezione03
 
TechTalk - Dotnet
TechTalk - DotnetTechTalk - Dotnet
TechTalk - Dotnet
 
Practices For Becoming A Better Programmer
Practices For Becoming A Better ProgrammerPractices For Becoming A Better Programmer
Practices For Becoming A Better Programmer
 
New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancement
 
Csharp4 basics
Csharp4 basicsCsharp4 basics
Csharp4 basics
 
Linq intro
Linq introLinq intro
Linq intro
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)
 
C++11 - STL Additions
C++11 - STL AdditionsC++11 - STL Additions
C++11 - STL Additions
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Core csharp and net quick reference
Core csharp and net quick referenceCore csharp and net quick reference
Core csharp and net quick reference
 

Plus de Mohamed Krar (18)

Csharp_Chap13
Csharp_Chap13Csharp_Chap13
Csharp_Chap13
 
Csharp_Chap14
Csharp_Chap14Csharp_Chap14
Csharp_Chap14
 
Csharp_Chap15
Csharp_Chap15Csharp_Chap15
Csharp_Chap15
 
Csharp_Contents
Csharp_ContentsCsharp_Contents
Csharp_Contents
 
Csharp_Intro
Csharp_IntroCsharp_Intro
Csharp_Intro
 
Csharp_Chap12
Csharp_Chap12Csharp_Chap12
Csharp_Chap12
 
Csharp_Chap11
Csharp_Chap11Csharp_Chap11
Csharp_Chap11
 
Csharp_Chap07
Csharp_Chap07Csharp_Chap07
Csharp_Chap07
 
Csharp_Chap08
Csharp_Chap08Csharp_Chap08
Csharp_Chap08
 
Csharp_Chap10
Csharp_Chap10Csharp_Chap10
Csharp_Chap10
 
Csharp_Chap09
Csharp_Chap09Csharp_Chap09
Csharp_Chap09
 
Csharp_Chap06
Csharp_Chap06Csharp_Chap06
Csharp_Chap06
 
Csharp_Chap05
Csharp_Chap05Csharp_Chap05
Csharp_Chap05
 
Csharp_Chap04
Csharp_Chap04Csharp_Chap04
Csharp_Chap04
 
Csharp_Chap03
Csharp_Chap03Csharp_Chap03
Csharp_Chap03
 
Csharp_Chap02
Csharp_Chap02Csharp_Chap02
Csharp_Chap02
 
Csharp_Chap01
Csharp_Chap01Csharp_Chap01
Csharp_Chap01
 
Csharp In Detail Part1
Csharp In Detail Part1Csharp In Detail Part1
Csharp In Detail Part1
 

Dernier

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 

Dernier (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 

Csharp In Detail Part2

  • 1. C# in Detail Jon Jagger Software Trainer, Designer, Consultant www.jaggersoft.com jon @ jaggersoft.com { JSL } Part 2
  • 2.
  • 3.
  • 4. string C# Programming Fundamentals Objects Relationships Systems
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. class C# Programming Fundamentals Objects Relationships Systems
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25. [ ] Arrays C# Programming Fundamentals Objects Relationships Systems
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35. Array Notes int [ ] illegal[ , ]; class Base {...} class Derived : Base {...} Derived[] ds = new Derived[]{...}; Base[] bs = ds; unsafe { int * array = stackalloc int [42]; ... } only one syntax C# supports array covariance you can create an array on the stack, but only in unsafe code object o = new int [42]; arrays are reference types int [ ][ , ] mixed; you can mix the two kinds of arrays
  • 36. Boxing C# Programming Fundamentals Objects Relationships Systems
  • 37.
  • 38. struct vs class struct Pair { int x, y; ... } Pair p = new Pair(1,2); Pair copy = p; p.x stack heap class Pair { int x, y; ... } Pair p = new Pair(1,2); Pair copy = p; 1 2 @ p @ copy 1 2 p.y copy.x copy.y .x 1 2 .y
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45. Inheritance C# Programming Fundamentals Objects Relationships Systems
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54. Interfaces C# Programming Fundamentals Objects Relationships Systems
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66. Abstract Classes C# Programming Fundamentals Objects Relationships Systems
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73. Exceptions C# Programming Fundamentals Objects Relationships Systems
  • 74.
  • 75. Hierarchy Exception ArithmeticException InvalidCastException DivideByZeroException OutOfMemoryException NullReferenceException OverflowException SystemException ... ExecutionEngineException IndexOutOfRangeException
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81. IDisposable struct AutoClosing : IDisposable { public AutoClosing(TextReader reader) { if (reader == null ) { throw new ArgumentNullException(); } target = reader; } public void Dispose() { target.Close(); } private readonly TextReader target; } interface IDisposable { void Dispose(); }
  • 82. Preference? ... TextReader reader = source.OpenText(); using ( new AutoClosing(reader)) { reader.Read(contents, 0, length); ... } TextReader reader = null ; try { ... reader = source.OpenText(); reader.Read(contents, 0, length); ... } finally { if (reader != null ) { reader.Close(); } } Before... ...After
  • 83.
  • 84.
  • 85. Garbage Collection C# Programming Fundamentals Objects Relationships Systems
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91. Nested Types C# Programming Fundamentals Objects Relationships Systems
  • 92.
  • 93.
  • 94.
  • 95.
  • 96. Delegates C# Programming Fundamentals Objects Relationships Systems
  • 97.
  • 98.
  • 99.
  • 100. Remember This? delegate void Method(); ... TextReader reader = source.OpenText(); using ( new Finally( new Method(reader.Close))) { reader.Read(contents, 0, length); ... } TextReader reader = null ; try { ... reader = source.OpenText(); reader.Read(contents, 0, length); ... } finally { if (reader != null ) { reader.Close(); } } ...After Before...
  • 101. Finally public delegate void Method(); public struct Finally : IDisposable { public Finally(Method call) { if (call == null ) { throw new ArgumentNullException(); } this .call = call; } public override void Dispose() { call(); } private readonly Method call; }
  • 102.
  • 103.
  • 104. Events C# Programming Fundamentals Objects Relationships Systems
  • 105.
  • 106.
  • 107.
  • 108.
  • 109. Namespaces C# Programming Fundamentals Objects Relationships Systems
  • 110.
  • 111.
  • 112.
  • 113.
  • 114. Assemblies C# Programming Fundamentals Objects Relationships Systems
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121. [Attributes] C# Programming Fundamentals Objects Relationships Systems
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132. Reflection C# Programming Fundamentals Objects Relationships Systems
  • 133.
  • 134.
  • 135. Remember This? TextReader reader = source.OpenText(); using ( new Finally(reader, &quot;Close&quot; )) { reader.Read(contents, 0, length); ... } TextReader reader = null ; try { ... reader = source.OpenText(); reader.Read(contents, 0, length); ... } finally { if (reader != null ) { reader.Close(); } } ...After
  • 136. Finally using System; using System.Reflection; public struct Finally : IDisposable { public Finally( object target, string methodName) { this .target = target; this .methodName = methodName; } public void Dispose() { Type t = target.GetType(); MethodInfo method = t.GetMethod(methodName); if (method != null ) { t.InvokeMember( methodName, BindingFlags.InvokeMethod, target, new object [0] ); } } private readonly object target; private readonly string methodName; }
  • 137.
  • 138.
  • 139.

Notes de l'éditeur

  1. ACCU Spring Conference, Christ Church College, Oxford, Friday 30 th March 2001. { JSL } Jagger Software Limited http://www.jaggersoft.com Tel . +44 (0) 1823 354 192 Hi, I&apos;m Jon Jagger, a freelance software trainer, designer, and consultant. I specialise in curly bracket languages, hence { JSL }. In a former life I was QA Training&apos;s C++ and C product consultant. I&apos;m an UK C++ standards panel member and a regular contributor to the ACCU Overload journal. I&apos;m married with three increasingly larger children. My interests include training excellence, design, problem solving, and monty python (which should be required knowledge for all software developers). Forget the technical interview, just recite the parrot sketch. I don&apos;t really know what else to say in a short bio such as this. I&apos;m very very good at sleeping. And breathing. Both of which I practice a lot.