SlideShare a Scribd company logo
1 of 116
Download to read offline
C#	
  3.0	
  &	
  4.0	
  

   Buu	
  Nguyen	
  
Buu	
  Nguyen	
  
•    Microso6	
  MVP	
  ASP.NET/IIS	
  2010,	
  2011	
  
•    Vice	
  President	
  of	
  Technology,	
  KMS	
  Technology	
  
•    IT	
  Lecturer,	
  RMIT	
  University	
  Vietnam	
  
•    www.buunguyen.net/blog	
  
•    @buunguyen	
  
Agenda	
  

•    .NET	
  and	
  CLR	
  
•    EvoluQon	
  of	
  C#	
  
•    C#	
  3.0	
  and	
  LINQ	
  
•    C#	
  4.0	
  and	
  Dynamic	
  Programming	
  
.NET	
  AND	
  CLR	
  
.NET	
  Framework	
  


C#	
       C++	
               VB.NET	
           IronRuby	
     ...	
  




                                                                           Visual	
  Studio	
  .NET	
  
                 Common	
  Type	
  System	
  &	
  	
  
         Common	
  Intermediate	
  Language	
  

                        	
  
         Common	
  Language	
  Specifica2on	
  

                     Base	
  Class	
  Libraries	
  

             Common	
  Language	
  Run2me	
  
CTS	
  and	
  CLS        	
  




•  The	
  Common	
  Type	
  System	
  (CTS)	
  specifies	
  type	
  
   rules	
  for	
  .NET	
  code.	
  	
  CIL	
  code	
  complies	
  with	
  
   CTS.	
  

•    The	
  Common	
  Language	
  SpecificaQon	
  (CLS),	
  a	
  
     subset	
  of	
  CTS,	
  assures	
  language	
  
     interoperability.	
  
CIL	
  
•  Stack-­‐based	
  language	
  
•  CIL	
  manipulaQon	
  enables	
  
   –  Dynamic	
  code	
  generaQon,	
  e.g.	
  Fasterflect	
  
   –  Code	
  instrumentaQon,	
  e.g.	
  test	
  coverage	
  tools	
  
   –  Decompilers,	
  obfuscators…	
  
InteresQng	
  Type	
  Concepts	
  
•    Value	
  types	
  vs.	
  reference	
  types	
  
•    Stack-­‐allocated	
  vs.	
  heap-­‐allocated	
  
•    Pass-­‐by-­‐value	
  vs.	
  pass-­‐by-­‐reference	
  
•    Delegate	
  vs.	
  event	
  types	
  
More	
  Types	
  Post	
  1.x	
  
•    ParQal	
  Types	
  (C#	
  2.0)	
  
•    Nullable	
  Types	
  (C#	
  2.0)	
  
•    Generic	
  Types	
  (C#	
  2.0)	
  
•    Dynamic	
  Types	
  (C#	
  4.0)	
  
EVOLUTION	
  OF	
  C#	
  
C#	
  Language	
  EvoluQon	
  


                                                                                                C#	
  5.0	
  
                                                                   C#	
  4.0	
                  	
  
                                                                                                         Async	
  
                                                                                                         CaaS	
  
                                                                           Dynamic	
  binding	
  (*)	
  
                                       C#	
  3.0	
                         Named	
  arguments	
  
                                                                           OpQonal	
  parameters	
  
                                            LINQ	
  (*)	
  
                                                                           Generic	
  variance	
  
                                            Auto-­‐	
  properQes	
  
                  C#	
  2.0	
               CollecQon	
  iniQalizer	
  
                                                                           Field-­‐like	
  events	
  
                                                                           Robust	
  locking	
  
                                            Object	
  iniQalizer	
  
                Generics	
  (*)	
                                          Beeer	
  COM	
  interop	
  
                                            Anonymous	
  types	
  
                Nullable	
  types	
  
                                            Extension	
  methods	
  
                Anonymous	
  methods	
  
C#	
  1.0	
     Yield	
  return	
  
                                            ParQal	
  methods	
  
                                            Lambda	
  expressions	
  
                ParQal	
  type	
  
                                            Expression	
  trees	
  
                StaQc	
  class	
  
                Namespace	
  alias	
  
DirecQon	
  
•  Concurrent	
  programming	
  
   –  FuncQonal-­‐style	
  programming	
  in	
  C#	
  3.0	
  
   –  PLINQ	
  in	
  .NET	
  4.0	
  
•  Dynamic	
  programming	
  
   –  Dynamic	
  binding	
  in	
  C#	
  4.0	
  and	
  CaaS	
  in	
  C#	
  5.0	
  
C#	
  3.0	
  
Features	
  
•    Implicitly-­‐typed	
  Local	
  Variables	
  
•    Implicitly-­‐typed	
  Arrays	
  
•    Auto-­‐implemented	
  ProperQes	
  
•    Object	
  IniQalizers	
  
•    CollecQon	
  IniQalizers	
  
•    ParQal	
  Methods	
  
•    Anonymous	
  Types	
  
•    Extension	
  Methods	
  
•    Lambda	
  Expressions	
  
•    Expression	
  Trees	
  
Implicitly-­‐typed	
  Local	
  Variables	
  


•  Benefits	
  
    –  DRY	
  (Don’t	
  Repeat	
  Yourself)	
  

•  SpecificaQons	
  
    –  Only	
  apply	
  to	
  local	
  variables	
  
    –  Must	
  be	
  iniQalized	
  with	
  an	
  non-­‐null	
  expression	
  

	
  
Implicitly-­‐typed	
  Arrays	
  

•  More	
  DRY	
  
Auto-­‐implemented	
  ProperQes	
  

•  AIP	
  allows	
  us	
  to	
  declare	
  properQes	
  with	
  no	
  
               implementaQon	
  and	
  no	
  backing	
  fields:	
  
               compiler	
  will	
  generate	
  code	
  for	
  them	
  
               automaQcally	
  
	
  
	
  	
  	
  	
  	
  
	
  	
  	
  	
  
Object	
  IniQalizers	
  

•  Combine	
  construcQon	
  and	
  property	
  assignments
CollecQon	
  IniQalizers	
  


•  Like	
  object	
  iniQalizer,	
  but	
  this	
  Qme	
  applies	
  to	
  
   collecQons	
  and	
  maps	
  
ParQal	
  Methods	
  

•  Method	
  contracts	
  
     –  Work	
  inside	
  parQal	
  classes	
  
     –  Must	
  be	
  private	
  &	
  return	
  void	
  
     –  Can	
  be	
  sta,c	
  or	
  non-­‐sta,c	
  
     –  Cannot	
  have	
  out	
  parameter	
  
        (support	
  ref	
  nonetheless)	
  
     –  Must	
  not	
  be	
  virtual,	
  abstract,	
  
        override,	
  sealed,	
  or	
  new	
  
•  Can	
  omit	
  the	
  implementaQon	
  
     –  All	
  calls	
  will	
  be	
  omieed	
  by	
  the	
  
        compiler	
  
Anonymous	
  Types	
  

•  This	
  feature	
  allows	
  us	
  to	
  quickly	
  create	
  objects	
  
   inside	
  a	
  method	
  without	
  declaring	
  their	
  
   corresponding	
  class	
  
Extension	
  Methods	
  

•  This	
  feature	
  enable	
  us	
  to	
  add	
  methods	
  to	
  
   exisQng	
  types.	
  	
  This	
  is	
  useful	
  when	
  
    –  We	
  don’t	
  have	
  access	
  to	
  source	
  code	
  of	
  a	
  type	
  
    –  The	
  type	
  is	
  sealed	
  and	
  can’t	
  be	
  inherited	
  
Lambda	
  Expressions	
  

•  Shorter	
  form	
  of	
  anonymous	
  methods
Expression	
  Trees	
  

•  Code	
  as	
  data	
  
    –  Enable	
  LINQ-­‐2-­‐SQL,	
  DLR…	
  
    –  Can	
  be	
  compiled	
  to	
  delegate	
  
    –  “Statement	
  trees”	
  are	
  supported	
  in	
  .NET	
  4.0	
  
LINQ	
  
Show	
  me	
  some	
  LINQ!	
  


var people =
  from p in GetSalesPeople()
  where p.HireDate > hireDate
  select p;

foreach (SalesPerson person in people)‫‏‬
{
  Console.WriteLine(person.FirstName);
}
LINQ	
  in	
  a	
  Nutshell	
  


Integrate	
  query	
  expressions	
  into	
  languages	
  

Unified	
  approach	
  to	
  query	
  data	
  

Declara2ve	
  style	
  of	
  coding	
  

Extensible	
  via	
  provider	
  mechanism	
  
How	
  is	
  LINQ	
  Implemented?	
  

•  LINQ	
  Query	
  Expressions	
  are	
  translated	
  to	
  normal	
  
   invocaQons	
  to	
  Standard	
  Query	
  Operators	
  
    	
  

            var contacts =
              from c in customers
              where c.State == "WA"
              select new { c.Name, c.Phone };


            var contacts =
             customers
             .Where(c => c.State == "WA")
             .Select(c => new { c.Name, c.Phone });
LINQ	
  &	
  C#	
  3.0	
  
            var contacts =
              from c in customers             Query Expression
              where c.State == "WA"
              select new { c.Name, c.Phone };
                   Implicitly-typed Local
                          Variable
                                                   Lambda
                                                  Expression
            var contacts =
             customers
             .Where(c => c.State == "WA")
             .Select(c => new { c.Name, c.Phone });

Extension                                          Object
 Method                                           Initializer
                Anonymous
                   Type
Where	
  Do	
  SQOs	
  Come	
  From?	
  

  §  Extensions	
  methods	
  for	
  
        IEnumerable<T>	
  defined	
  in	
  
        System.Linq.Enumerable

  §  Building	
  a	
  LINQ-­‐enabled	
  data	
  source	
  is	
  
        as	
  simple	
  as	
  having	
  your	
  class	
  
        implemenQng	
  IEnumerable<T>	
  
	
  
LINQ	
  Clauses	
  

                               from	
  	
  

       let	
                                          where	
  




join	
                                                     select	
  




                 orderby	
                    group	
  
Structure	
  of	
  LINQ	
  Queries	
  
First	
  Line	
  

• from	
  clause	
  

Middle	
  Lines	
  

• from,	
  where,	
  orderby,	
  join,	
  let	
  clauses	
  

Last	
  Line	
  

• select	
  or	
  group-by	
  clause	
  
LINQ	
  Architecture	
  
Visual Basic                          C#                        Others…


                   .NET Language-Integrated Query


                            LINQ to ADO.NET


  LINQ                                                               LINQ
                  LINQ             LINQ              LINQ           to XML
to Object
                 to SQL         to DataSet        to Entities




                                                                 <book>	
  
                                                                 	
  	
  	
  	
  <Qtle/>	
  
                                                                 	
  	
  	
  	
  <author/>	
  
                                                                 	
  	
  	
  	
  <year/>	
  
                                                                 	
  	
  	
  	
  <price/>	
  
                                                                 </book>	
  


 Objects	
                  RelaQonal	
  DB	
                           XML	
  
IEnumerable<T>	
  
                       from	
  itemName	
  in	
  srcExpr	
  
Object	
               where	
  predExpr	
  
 Object	
              orderby	
  (keyExpr	
  (ascending	
  |	
  descending))	
  
   Object	
  
   Objects	
  in	
  
   Memory	
            select	
  selExpr	
  
                       ...	
  



  where	
  

  where	
  
  orderby	
  

  where	
  
  orderby	
  
    select	
  
                 IQueryable<T>	
  
Nothing	
  	
  
  In	
  
                              	
  
                  from	
  itemName	
  in	
  srcExpr	
  
                  where	
  predExpr	
  
                  orderby	
  (keyExpr	
  (ascending	
  |	
  descending))	
  
Memory	
  
                  select	
  selExpr	
  
                  ...	
  


                                 “FROM	
  [srcExpr]	
  WHERE	
  ...”	
  
where	
  
                                 FROM	
  [srcExpr]	
  WHERE	
  predExpr	
  
where	
                          ORDER	
  BY	
  [keyExpr]”	
  
orderby	
  
                                 SELECT	
  [selExpr]	
  
where	
                          FROM	
  [srcExpr]	
  WHERE	
  predExpr	
  
                                 ORDER	
  BY	
  [keyExpr]”	
  
orderby	
  
  select	
  
Deferred	
  vs.	
  Non-­‐deferred	
  Operators	
  

Deferred	
                                               Non-­‐deferred	
  
•  Rule	
  of	
  thumb:	
  LINQ	
  query	
  syntax	
  	
   •  Rule	
  of	
  thumb:	
  scalar/single-­‐value	
  
   or	
  IEnumerable<T>	
  return	
                           return	
  or	
  conversion	
  
•    AsEnumerable, Cast,                                 •    Aggregate, All, Any,
     Concat, DefaultIfEmpty,                                  Average, Contains, Count,
     Distinct, Empty, Except,                                 ElementAt,
     GroupBy, GroupJoin,                                      ElementAtOrDefault, Last,
     Intersect, Join, OfType,                                 LastOrDefault, LongCount,
     OrderBy,                                                 Max, Min, Single,
     OrderByDescending, Range,                                SingleOrDefault, Sum,
     Repeat, Reverse, Select,                                 ToArray, ToDictionary,
     SelectMany, Skip,                                        ToList, ToLookup
     SkipWhile, Take,
     TakeWhile, ThenBy,
     ThenByDescending, Union,
     Where

                                                                                                                  36	
  
C#	
  4.0	
  
Features	
  Covered	
  
•    OpQonal	
  Parameters	
  
•    Named	
  Arguments	
  
•    Beeer	
  COM	
  Interop	
  
•    Generic	
  Variance	
  
•    Robust	
  Locking	
  
•    Field-­‐like	
  Events	
  
OPTIONAL	
  PARAMETERS	
  
How	
  to	
  implement	
  MailMessage()?	
  
Overloading	
  
OpQonal	
  Parameters	
  
OpQonal	
  Values	
  
•    Numeric	
  and	
  string	
  literals	
  
•    null	
  
•    Compile-­‐Qme	
  constants	
  
•    Enum	
  members	
  
•    default(T)	
  
•    Parameterless	
  constructor	
  for	
  structs	
  
RestricQons	
  
•  OpQonal	
  parameters	
  must	
  come	
  a6er	
  
   required	
  parameters	
  
    –  Except	
  for	
  parameter	
  array	
  (empty	
  array	
  is	
  used	
  
       when	
  not	
  specified)	
  


•  OpQonal	
  parameters	
  can’t	
  be	
  ref	
  or	
  out	
  
In	
  Depth:	
  DefiniQon	
  Site	
  
In	
  Depth:	
  Call	
  Site	
  
Consequence	
  
•  OpQonal	
  values	
  are	
  part	
  of	
  the	
  published	
  API,	
  
   if	
  they	
  are	
  changed,	
  client	
  code	
  must	
  be	
  
   recompiled.	
  	
  Worse,	
  the	
  compiler	
  won’t	
  warn	
  
   you	
  if	
  you	
  don’t	
  change.	
  
NAMED	
  ARGUMENTS	
  
How	
  to	
  Avoid	
  the	
  Comments?	
  
Object	
  IniQalizer	
  
Named	
  Arguments	
  
…Named	
  Arguments	
  
RestricQons	
  
•  PosiQonal	
  arguments	
  must	
  come	
  before	
  
   named	
  arguments	
  
Under	
  the	
  Hood	
  
•  The	
  compiler	
  just	
  reorders,	
  that’s	
  all	
  
Consequence	
  
•  Parameter	
  names	
  are	
  part	
  of	
  the	
  published	
  
   API,	
  if	
  they	
  are	
  changed,	
  client	
  code	
  must	
  be	
  
   changed.	
  
BETTER	
  COM	
  INTEROPERABILITY	
  
How	
  Do	
  You	
  Like	
  This?	
  
#1:	
  Omit	
  ref	
  
#2:	
  OpQonal	
  Parameters	
  
GENERIC	
  VARIANCE	
  
Is	
  This	
  Okay?	
  
No,	
  because…	
  
Generic	
  Covariance	
  
•  Generic	
  covariance	
  reserves	
  assignment	
  
   compaQbility	
  on	
  generic	
  types	
  
    –  If	
  T1	
  is	
  a	
  subtype	
  of	
  T2,	
  GT<T1>	
  behaves	
  like	
  
       subtype	
  of	
  GT<T2>	
  on	
  assignment	
  


•  Safe	
  only	
  when	
  GT	
  doesn’t	
  “take	
  in”	
  any	
  T	
  
Example	
  
On	
  Delegate	
  
Is	
  This	
  Okay?	
  
No,	
  because…	
  
Generic	
  Contravariance	
  
•  Generic	
  covariance	
  reverses	
  assignment	
  
   compaQbility	
  on	
  generic	
  types	
  
    –  If	
  T1	
  is	
  a	
  subtype	
  of	
  T2,	
  GT<T1>	
  behaves	
  like	
  
       supertype	
  of	
  GT<T2>	
  on	
  assignment	
  

•  Safe	
  only	
  when	
  GT	
  doesn’t	
  return	
  any	
  T	
  
Example	
  
On	
  Delegate	
  
Under	
  the	
  Hood	
  
ROBUST	
  LOCKING	
  
Problem	
  




If	
  the	
  thread	
  is	
  aborted	
  a>er	
  the	
  lock	
  is	
  acquired	
  but	
  before	
  we	
  enter	
  
the	
  try	
  block,	
  we	
  won’t	
  have	
  released	
  the	
  lock.	
  
SoluQon	
  
FIELD-­‐LIKE	
  EVENTS	
  
The	
  Problem	
  




Lock	
  on	
  ‘this’	
  is	
  bad.	
  	
  Lock	
  on	
  ‘type’	
  is	
  bad.	
  
The	
  SoluQon	
  




A	
  simple	
  lock	
  would	
  work,	
  but	
  this	
  is	
  beeer	
  because	
  it’s	
  lock-­‐free.	
  
DYNAMIC	
  BINDING	
  
WHAT	
  IS	
  DYNAMIC	
  BINDING	
  
StaQc	
  vs.	
  Dynamic	
  Binding	
  
Sta2c	
  Binding	
                            Dynamic	
  Biding	
  
•  Compiler	
  figures	
  out	
  which	
       •  All	
  bindings	
  happen	
  during	
  
   members	
  to	
  call	
  (binding	
           run	
  Qme	
  
   process)	
  
     –  Defer	
  subtype	
  polymorphic	
  
        resoluQon	
  Qll	
  run	
  Qme	
  
StaQc	
  Binding	
  
Benefits	
  of	
  StaQc	
  Binding	
  
•  Type	
  and	
  name	
  errors	
  are	
  detected	
  at	
  compile	
  
   Qme,	
  e.g.	
  
    –  Invoke	
  non-­‐existent	
  members	
  
    –  Pass	
  in	
  arguments	
  with	
  wrong	
  type	
  
    –  Perform	
  illegal	
  cast	
  
Dynamic	
  Binding	
  
HOW	
  IS	
  IT	
  IMPLEMENTED?	
  
Run	
  Time	
  Binding	
  
•  Instead	
  of	
  aeempQng	
  binding	
  and	
  generaQng	
  
   CIL,	
  the	
  compiler	
  packages	
  the	
  call	
  and	
  sends	
  
   it	
  to	
  the	
  Dynamic	
  Language	
  RunQme	
  	
  
•  At	
  run	
  Qme,	
  the	
  DLR	
  performs	
  binding	
  and	
  
   execuQon	
  
Under	
  the	
  Hood	
  

becomes	
  
The	
  Dynamic	
  Language	
  RunQme	
  
Process	
  in	
  a	
  nutshell	
  
    C#	
  
  dynamic	
                         Dynamic	
                         builds	
  
                                    Objects	
  
                                                       User-­‐defined	
  or	
  from	
  other	
  languages	
  
          compiled	
  

                       uses	
       IDynamicMetaObjectProvider	
  
  Call	
  Sites	
  

          cached	
  
                                                                                                                           Delegate	
  
                                                                                      Expression	
             emits	
  
                                                                                         Tree	
  

DLR	
  
                                    C#	
  Binder	
                  builds	
  
Dynamic	
  Type	
  in	
  CIL	
  
WHEN	
  DO	
  WE	
  NEED	
  IT?	
  
Key	
  Scenarios	
  
1.  Access	
  a	
  member	
  with	
  only	
  knowledge	
  of	
  its	
  
    name,	
  arguments,	
  and	
  target	
  object	
  

2.  Interop	
  with	
  dynamic	
  languages,	
  e.g.	
  
    IronRuby,	
  IronPython	
  

3.  Have	
  the	
  target	
  object	
  decide	
  how	
  to	
  
    respond	
  to	
  a	
  call	
  at	
  run	
  Qme	
  
Key	
  Scenarios	
  
1.  Access	
  a	
  member	
  with	
  only	
  knowledge	
  of	
  its	
  
    name,	
  arguments,	
  and	
  target	
  object	
  

2.  Interop	
  with	
  dynamic	
  languages,	
  e.g.	
  
    IronRuby,	
  IronPython	
  

3.  Have	
  the	
  target	
  object	
  decide	
  how	
  to	
  
    respond	
  to	
  a	
  call	
  at	
  run	
  Qme	
  
Access	
  Members	
  
ReflecQon	
  
Dynamic	
  Type	
  
Single	
  vs.	
  MulQple	
  Dispatch	
  
Single	
  Dispatch	
                              Mul2ple	
  Dispatch	
  
•  Method	
  is	
  selected	
  based	
            •  Method	
  is	
  selected	
  based	
  
   on	
  the	
  runQme	
  type	
  of	
  the	
        on	
  both	
  the	
  runQme	
  type	
  of	
  
   target	
  object	
                                the	
  target	
  object	
  and	
  those	
  
                                                     of	
  the	
  method’s	
  arguments	
  
Dispatch	
  Example	
  
Key	
  Scenarios	
  
1.  Access	
  a	
  member	
  with	
  only	
  knowledge	
  of	
  its	
  
    name,	
  arguments,	
  and	
  target	
  object	
  

2.  Interop	
  with	
  dynamic	
  languages,	
  e.g.	
  
    IronRuby,	
  IronPython	
  

3.  Have	
  the	
  target	
  object	
  decide	
  how	
  to	
  
    respond	
  to	
  a	
  call	
  at	
  run	
  Qme	
  
Invoke	
  Ruby	
  Code	
  
Work	
  with	
  Ruby	
  Class	
  
Work	
  with	
  method_missing	
  
Key	
  Scenarios	
  
1.  Access	
  a	
  member	
  with	
  only	
  knowledge	
  of	
  its	
  
    name,	
  arguments,	
  and	
  target	
  object	
  

2.  Interop	
  with	
  dynamic	
  languages,	
  e.g.	
  
    IronRuby,	
  IronPython	
  

3.  Have	
  the	
  target	
  object	
  decide	
  how	
  to	
  
    respond	
  to	
  a	
  call	
  at	
  run	
  Qme	
  
The	
  Magic	
  Interface	
  


IDynamicMetaObjectProvider	
  


                            ExpandoObject	
  


                            DynamicObject	
  
ExpandoObject	
  
DynamicObject’s	
  OperaQons	
  
Name	
                  Descrip2on	
  
TryGetMember	
          Member	
  geeer,	
  e.g.	
  obj.Name	
  
TrySetMember	
          Member	
  seeer,	
  e.g.	
  obj.age	
  =	
  10	
  
TryDeleteMember	
       Member	
  removal	
  (no	
  equivalent	
  in	
  C#)	
  
TryInvokeMember	
       Method	
  invocaQon,	
  e.g.	
  obj.Invoke()	
  
TryConvert	
            CasQng,	
  e.g.	
  (int)obj	
  
TryCreateInstance	
     Object	
  creaQon	
  (no	
  equivalent	
  in	
  C#)	
  
TryInvoke	
             Self	
  invocaQon,	
  e.g.	
  obj(10)	
  
TryBinaryOperaQon	
     Binary	
  operaQon,	
  e.g.	
  obj	
  +	
  10	
  
TryUnaryOperaQon	
      Unary	
  operaQon,	
  e.g.	
  !obj	
  
TryGetIndex	
           Indexer	
  geeer,	
  e.g.	
  obj[“key”]	
  
TrySetIndex	
           Indexer	
  seeer,	
  e.g.	
  obj[“key”]	
  =	
  value	
  
TryDeleteIndex	
        Indexer	
  removal	
  (no	
  equivalent	
  in	
  C#)	
  
Log	
  Seeers	
  &	
  InvocaQons	
  
StaQcInvoker	
  
StaQcInvoker	
  
Close	
  to	
  the	
  metal	
  
…Close	
  to	
  the	
  metal	
  
…Close	
  to	
  the	
  metal	
  
RESTRICTIONS	
  
RestricQon	
  #1	
  
•  Doesn’t	
  work	
  with	
  extension	
  methods	
  
RestricQon	
  #2	
  
•  Can’t	
  resolve	
  staQc	
  members	
  or	
  constructors	
  
   on	
  a	
  dynamic	
  type	
  
RestricQon	
  #3	
  
•  Method	
  groups,	
  anonymous	
  methods	
  and	
  lambda	
  
   expressions	
  to	
  be	
  casted	
  to	
  exact	
  type	
  
RestricQon	
  #4	
  

More Related Content

What's hot (20)

The Evolution of Scala
The Evolution of ScalaThe Evolution of Scala
The Evolution of Scala
 
Distributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMIDistributed Objects: CORBA/Java RMI
Distributed Objects: CORBA/Java RMI
 
Java RMI Detailed Tutorial
Java RMI Detailed TutorialJava RMI Detailed Tutorial
Java RMI Detailed Tutorial
 
C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New FeaturesC#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Features
 
Turmeric SOA Cloud Mashups
Turmeric SOA Cloud MashupsTurmeric SOA Cloud Mashups
Turmeric SOA Cloud Mashups
 
Distributed objects
Distributed objectsDistributed objects
Distributed objects
 
Chapter 17 corba
Chapter 17 corbaChapter 17 corba
Chapter 17 corba
 
CORBA
CORBACORBA
CORBA
 
internet
internetinternet
internet
 
C#unit4
C#unit4C#unit4
C#unit4
 
Corba by Example
Corba by ExampleCorba by Example
Corba by Example
 
Rmi ppt-2003
Rmi ppt-2003Rmi ppt-2003
Rmi ppt-2003
 
COM
COMCOM
COM
 
Presentation On Com Dcom
Presentation On Com DcomPresentation On Com Dcom
Presentation On Com Dcom
 
Introduction to Remote Method Invocation (RMI)
Introduction to Remote Method Invocation (RMI)Introduction to Remote Method Invocation (RMI)
Introduction to Remote Method Invocation (RMI)
 
C O R B A Unit 4
C O R B A    Unit 4C O R B A    Unit 4
C O R B A Unit 4
 
D1 from interfaces to solid
D1 from interfaces to solidD1 from interfaces to solid
D1 from interfaces to solid
 
Java Training in Noida Delhi NCR BY Ducat
Java Training in Noida Delhi NCR BY DucatJava Training in Noida Delhi NCR BY Ducat
Java Training in Noida Delhi NCR BY Ducat
 
Corba model ppt
Corba model pptCorba model ppt
Corba model ppt
 
05 rpc-case studies
05 rpc-case studies05 rpc-case studies
05 rpc-case studies
 

Viewers also liked

Native i os, android, and windows development in c# with xamarin 4
Native i os, android, and windows development in c# with xamarin 4Native i os, android, and windows development in c# with xamarin 4
Native i os, android, and windows development in c# with xamarin 4Xamarin
 
Python mu Java mı?
Python mu Java mı?Python mu Java mı?
Python mu Java mı?aerkanc
 
Ruby - Dünyanın En Güzel Programlama Dili
Ruby - Dünyanın En Güzel Programlama DiliRuby - Dünyanın En Güzel Programlama Dili
Ruby - Dünyanın En Güzel Programlama DiliSerdar Dogruyol
 
XAML Development with Xamarin - Jesse Liberty | FalafelCON 2014
XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014
XAML Development with Xamarin - Jesse Liberty | FalafelCON 2014FalafelSoftware
 
Formation C# & XAML
Formation C# & XAML Formation C# & XAML
Formation C# & XAML Hiba GHADHAB
 
Comparing xaml and html
Comparing xaml and htmlComparing xaml and html
Comparing xaml and htmlKevin DeRudder
 
Ruby Programlama Dili
Ruby Programlama DiliRuby Programlama Dili
Ruby Programlama Dilipinguar
 
Build your own Cloud/Home security system for 60$
Build your own Cloud/Home security system for 60$Build your own Cloud/Home security system for 60$
Build your own Cloud/Home security system for 60$Kevin DeRudder
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#Hawkman Academy
 
Introduction to C# 6.0 and 7.0
Introduction to C# 6.0 and 7.0Introduction to C# 6.0 and 7.0
Introduction to C# 6.0 and 7.0Saineshwar bageri
 
Switch to Results in Hotels
Switch to Results in HotelsSwitch to Results in Hotels
Switch to Results in HotelsJack Watson
 
Xamarin Cross-Platform with Xamarin.Form, MvvmCross
Xamarin Cross-Platform with Xamarin.Form, MvvmCrossXamarin Cross-Platform with Xamarin.Form, MvvmCross
Xamarin Cross-Platform with Xamarin.Form, MvvmCrossTri Nguyen
 
Xamarin 3 hieu 19-06
Xamarin 3   hieu 19-06Xamarin 3   hieu 19-06
Xamarin 3 hieu 19-06Nguyen Hieu
 

Viewers also liked (20)

Native i os, android, and windows development in c# with xamarin 4
Native i os, android, and windows development in c# with xamarin 4Native i os, android, and windows development in c# with xamarin 4
Native i os, android, and windows development in c# with xamarin 4
 
ASP.MVC Training
ASP.MVC TrainingASP.MVC Training
ASP.MVC Training
 
Python mu Java mı?
Python mu Java mı?Python mu Java mı?
Python mu Java mı?
 
Ruby - Dünyanın En Güzel Programlama Dili
Ruby - Dünyanın En Güzel Programlama DiliRuby - Dünyanın En Güzel Programlama Dili
Ruby - Dünyanın En Güzel Programlama Dili
 
XAML Development with Xamarin - Jesse Liberty | FalafelCON 2014
XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014XAML Development with Xamarin  - Jesse Liberty | FalafelCON 2014
XAML Development with Xamarin - Jesse Liberty | FalafelCON 2014
 
Formation C# & XAML
Formation C# & XAML Formation C# & XAML
Formation C# & XAML
 
Comparing xaml and html
Comparing xaml and htmlComparing xaml and html
Comparing xaml and html
 
Ruby Programlama Dili
Ruby Programlama DiliRuby Programlama Dili
Ruby Programlama Dili
 
Build your own Cloud/Home security system for 60$
Build your own Cloud/Home security system for 60$Build your own Cloud/Home security system for 60$
Build your own Cloud/Home security system for 60$
 
Formation VB.NET
Formation VB.NETFormation VB.NET
Formation VB.NET
 
C sharp chap1
C sharp chap1C sharp chap1
C sharp chap1
 
C#
C#C#
C#
 
Agile Retrospectives
Agile RetrospectivesAgile Retrospectives
Agile Retrospectives
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
Introduction to C# 6.0 and 7.0
Introduction to C# 6.0 and 7.0Introduction to C# 6.0 and 7.0
Introduction to C# 6.0 and 7.0
 
Switch to Results in Hotels
Switch to Results in HotelsSwitch to Results in Hotels
Switch to Results in Hotels
 
Xamarin Cross-Platform with Xamarin.Form, MvvmCross
Xamarin Cross-Platform with Xamarin.Form, MvvmCrossXamarin Cross-Platform with Xamarin.Form, MvvmCross
Xamarin Cross-Platform with Xamarin.Form, MvvmCross
 
Xamarin 3 hieu 19-06
Xamarin 3   hieu 19-06Xamarin 3   hieu 19-06
Xamarin 3 hieu 19-06
 
C# Is The Future
C# Is The FutureC# Is The Future
C# Is The Future
 
C#
C#C#
C#
 

Similar to C# 3.0 and 4.0

Net framework
Net frameworkNet framework
Net frameworkTuan Ngo
 
Overview Of .Net 4.0 Sanjay Vyas
Overview Of .Net 4.0   Sanjay VyasOverview Of .Net 4.0   Sanjay Vyas
Overview Of .Net 4.0 Sanjay Vyasrsnarayanan
 
Windows 8 für .net Entwickler
Windows 8 für .net EntwicklerWindows 8 für .net Entwickler
Windows 8 für .net EntwicklerPatric Boscolo
 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java DevelopersMuhammad Abdullah
 
Binding Objective-C Libraries, Miguel de Icaza
Binding Objective-C Libraries, Miguel de IcazaBinding Objective-C Libraries, Miguel de Icaza
Binding Objective-C Libraries, Miguel de IcazaXamarin
 
Auto cad 2006_api_overview
Auto cad 2006_api_overviewAuto cad 2006_api_overview
Auto cad 2006_api_overviewscdhruv5
 
Understanding LINQ in C#
Understanding LINQ in C# Understanding LINQ in C#
Understanding LINQ in C# MD. Shohag Mia
 
C# advanced topics and future - C#5
C# advanced topics and future - C#5C# advanced topics and future - C#5
C# advanced topics and future - C#5Peter Gfader
 
Hidden Facts of .NET Language Gems
Hidden Facts of .NET Language GemsHidden Facts of .NET Language Gems
Hidden Facts of .NET Language GemsAbhishek Sur
 
NDepend Public PPT (2008)
NDepend Public PPT (2008)NDepend Public PPT (2008)
NDepend Public PPT (2008)NDepend
 
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)ssuser7f90ae
 
Clean Infrastructure as Code
Clean Infrastructure as CodeClean Infrastructure as Code
Clean Infrastructure as CodeQAware GmbH
 
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
 

Similar to C# 3.0 and 4.0 (20)

Net framework
Net frameworkNet framework
Net framework
 
C#4.0 features
C#4.0 featuresC#4.0 features
C#4.0 features
 
Overview Of .Net 4.0 Sanjay Vyas
Overview Of .Net 4.0   Sanjay VyasOverview Of .Net 4.0   Sanjay Vyas
Overview Of .Net 4.0 Sanjay Vyas
 
Windows 8 für .net Entwickler
Windows 8 für .net EntwicklerWindows 8 für .net Entwickler
Windows 8 für .net Entwickler
 
Introduction to C# 3.0
Introduction to C# 3.0Introduction to C# 3.0
Introduction to C# 3.0
 
Why do I Love C#?
Why do I Love C#?Why do I Love C#?
Why do I Love C#?
 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java Developers
 
Binding Objective-C Libraries, Miguel de Icaza
Binding Objective-C Libraries, Miguel de IcazaBinding Objective-C Libraries, Miguel de Icaza
Binding Objective-C Libraries, Miguel de Icaza
 
Auto cad 2006_api_overview
Auto cad 2006_api_overviewAuto cad 2006_api_overview
Auto cad 2006_api_overview
 
Understanding LINQ in C#
Understanding LINQ in C# Understanding LINQ in C#
Understanding LINQ in C#
 
C# advanced topics and future - C#5
C# advanced topics and future - C#5C# advanced topics and future - C#5
C# advanced topics and future - C#5
 
Hidden Facts of .NET Language Gems
Hidden Facts of .NET Language GemsHidden Facts of .NET Language Gems
Hidden Facts of .NET Language Gems
 
NDepend Public PPT (2008)
NDepend Public PPT (2008)NDepend Public PPT (2008)
NDepend Public PPT (2008)
 
C# tutorial
C# tutorialC# tutorial
C# tutorial
 
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)
21UCAC61 C# and .Net Programming.pdf(MTNC)(BCA)
 
Link quries
Link quriesLink quries
Link quries
 
Clean Infrastructure as Code
Clean Infrastructure as CodeClean Infrastructure as Code
Clean Infrastructure as Code
 
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)
 
Cs30 New
Cs30 NewCs30 New
Cs30 New
 
Csharp
CsharpCsharp
Csharp
 

More from Buu Nguyen

On Becoming a Technical Lead
On Becoming a Technical LeadOn Becoming a Technical Lead
On Becoming a Technical LeadBuu Nguyen
 
Stories about KMS Technology
Stories about KMS TechnologyStories about KMS Technology
Stories about KMS TechnologyBuu Nguyen
 
Dynamic Binding in C# 4.0
Dynamic Binding in C# 4.0Dynamic Binding in C# 4.0
Dynamic Binding in C# 4.0Buu Nguyen
 
ASP.NET MVC 2.0
ASP.NET MVC 2.0ASP.NET MVC 2.0
ASP.NET MVC 2.0Buu Nguyen
 
Building Scalable .NET Web Applications
Building Scalable .NET Web ApplicationsBuilding Scalable .NET Web Applications
Building Scalable .NET Web ApplicationsBuu Nguyen
 
New Features of ASP.NET 4.0
New Features of ASP.NET 4.0New Features of ASP.NET 4.0
New Features of ASP.NET 4.0Buu Nguyen
 
C# 4.0 and .NET 4.0
C# 4.0 and .NET 4.0C# 4.0 and .NET 4.0
C# 4.0 and .NET 4.0Buu Nguyen
 

More from Buu Nguyen (11)

On Becoming a Technical Lead
On Becoming a Technical LeadOn Becoming a Technical Lead
On Becoming a Technical Lead
 
Stories about KMS Technology
Stories about KMS TechnologyStories about KMS Technology
Stories about KMS Technology
 
ASP.NET MVC 3
ASP.NET MVC 3ASP.NET MVC 3
ASP.NET MVC 3
 
HTML5 in IE9
HTML5 in IE9HTML5 in IE9
HTML5 in IE9
 
Dynamic Binding in C# 4.0
Dynamic Binding in C# 4.0Dynamic Binding in C# 4.0
Dynamic Binding in C# 4.0
 
ASP.NET MVC 2.0
ASP.NET MVC 2.0ASP.NET MVC 2.0
ASP.NET MVC 2.0
 
Building Scalable .NET Web Applications
Building Scalable .NET Web ApplicationsBuilding Scalable .NET Web Applications
Building Scalable .NET Web Applications
 
New Features of ASP.NET 4.0
New Features of ASP.NET 4.0New Features of ASP.NET 4.0
New Features of ASP.NET 4.0
 
C# 4.0 and .NET 4.0
C# 4.0 and .NET 4.0C# 4.0 and .NET 4.0
C# 4.0 and .NET 4.0
 
Combres
CombresCombres
Combres
 
Fasterflect
FasterflectFasterflect
Fasterflect
 

Recently uploaded

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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
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
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Recently uploaded (20)

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 ...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
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
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
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...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 

C# 3.0 and 4.0

  • 1. C#  3.0  &  4.0   Buu  Nguyen  
  • 2. Buu  Nguyen   •  Microso6  MVP  ASP.NET/IIS  2010,  2011   •  Vice  President  of  Technology,  KMS  Technology   •  IT  Lecturer,  RMIT  University  Vietnam   •  www.buunguyen.net/blog   •  @buunguyen  
  • 3. Agenda   •  .NET  and  CLR   •  EvoluQon  of  C#   •  C#  3.0  and  LINQ   •  C#  4.0  and  Dynamic  Programming  
  • 5. .NET  Framework   C#   C++   VB.NET   IronRuby   ...   Visual  Studio  .NET   Common  Type  System  &     Common  Intermediate  Language     Common  Language  Specifica2on   Base  Class  Libraries   Common  Language  Run2me  
  • 6. CTS  and  CLS   •  The  Common  Type  System  (CTS)  specifies  type   rules  for  .NET  code.    CIL  code  complies  with   CTS.   •  The  Common  Language  SpecificaQon  (CLS),  a   subset  of  CTS,  assures  language   interoperability.  
  • 7. CIL   •  Stack-­‐based  language   •  CIL  manipulaQon  enables   –  Dynamic  code  generaQon,  e.g.  Fasterflect   –  Code  instrumentaQon,  e.g.  test  coverage  tools   –  Decompilers,  obfuscators…  
  • 8. InteresQng  Type  Concepts   •  Value  types  vs.  reference  types   •  Stack-­‐allocated  vs.  heap-­‐allocated   •  Pass-­‐by-­‐value  vs.  pass-­‐by-­‐reference   •  Delegate  vs.  event  types  
  • 9. More  Types  Post  1.x   •  ParQal  Types  (C#  2.0)   •  Nullable  Types  (C#  2.0)   •  Generic  Types  (C#  2.0)   •  Dynamic  Types  (C#  4.0)  
  • 11. C#  Language  EvoluQon   C#  5.0   C#  4.0     Async   CaaS   Dynamic  binding  (*)   C#  3.0   Named  arguments   OpQonal  parameters   LINQ  (*)   Generic  variance   Auto-­‐  properQes   C#  2.0   CollecQon  iniQalizer   Field-­‐like  events   Robust  locking   Object  iniQalizer   Generics  (*)   Beeer  COM  interop   Anonymous  types   Nullable  types   Extension  methods   Anonymous  methods   C#  1.0   Yield  return   ParQal  methods   Lambda  expressions   ParQal  type   Expression  trees   StaQc  class   Namespace  alias  
  • 12. DirecQon   •  Concurrent  programming   –  FuncQonal-­‐style  programming  in  C#  3.0   –  PLINQ  in  .NET  4.0   •  Dynamic  programming   –  Dynamic  binding  in  C#  4.0  and  CaaS  in  C#  5.0  
  • 14. Features   •  Implicitly-­‐typed  Local  Variables   •  Implicitly-­‐typed  Arrays   •  Auto-­‐implemented  ProperQes   •  Object  IniQalizers   •  CollecQon  IniQalizers   •  ParQal  Methods   •  Anonymous  Types   •  Extension  Methods   •  Lambda  Expressions   •  Expression  Trees  
  • 15. Implicitly-­‐typed  Local  Variables   •  Benefits   –  DRY  (Don’t  Repeat  Yourself)   •  SpecificaQons   –  Only  apply  to  local  variables   –  Must  be  iniQalized  with  an  non-­‐null  expression    
  • 17. Auto-­‐implemented  ProperQes   •  AIP  allows  us  to  declare  properQes  with  no   implementaQon  and  no  backing  fields:   compiler  will  generate  code  for  them   automaQcally                      
  • 18. Object  IniQalizers   •  Combine  construcQon  and  property  assignments
  • 19. CollecQon  IniQalizers   •  Like  object  iniQalizer,  but  this  Qme  applies  to   collecQons  and  maps  
  • 20. ParQal  Methods   •  Method  contracts   –  Work  inside  parQal  classes   –  Must  be  private  &  return  void   –  Can  be  sta,c  or  non-­‐sta,c   –  Cannot  have  out  parameter   (support  ref  nonetheless)   –  Must  not  be  virtual,  abstract,   override,  sealed,  or  new   •  Can  omit  the  implementaQon   –  All  calls  will  be  omieed  by  the   compiler  
  • 21. Anonymous  Types   •  This  feature  allows  us  to  quickly  create  objects   inside  a  method  without  declaring  their   corresponding  class  
  • 22. Extension  Methods   •  This  feature  enable  us  to  add  methods  to   exisQng  types.    This  is  useful  when   –  We  don’t  have  access  to  source  code  of  a  type   –  The  type  is  sealed  and  can’t  be  inherited  
  • 23. Lambda  Expressions   •  Shorter  form  of  anonymous  methods
  • 24. Expression  Trees   •  Code  as  data   –  Enable  LINQ-­‐2-­‐SQL,  DLR…   –  Can  be  compiled  to  delegate   –  “Statement  trees”  are  supported  in  .NET  4.0  
  • 26. Show  me  some  LINQ!   var people = from p in GetSalesPeople() where p.HireDate > hireDate select p; foreach (SalesPerson person in people)‫‏‬ { Console.WriteLine(person.FirstName); }
  • 27. LINQ  in  a  Nutshell   Integrate  query  expressions  into  languages   Unified  approach  to  query  data   Declara2ve  style  of  coding   Extensible  via  provider  mechanism  
  • 28. How  is  LINQ  Implemented?   •  LINQ  Query  Expressions  are  translated  to  normal   invocaQons  to  Standard  Query  Operators     var contacts = from c in customers where c.State == "WA" select new { c.Name, c.Phone }; var contacts = customers .Where(c => c.State == "WA") .Select(c => new { c.Name, c.Phone });
  • 29. LINQ  &  C#  3.0   var contacts = from c in customers Query Expression where c.State == "WA" select new { c.Name, c.Phone }; Implicitly-typed Local Variable Lambda Expression var contacts = customers .Where(c => c.State == "WA") .Select(c => new { c.Name, c.Phone }); Extension Object Method Initializer Anonymous Type
  • 30. Where  Do  SQOs  Come  From?   §  Extensions  methods  for   IEnumerable<T>  defined  in   System.Linq.Enumerable §  Building  a  LINQ-­‐enabled  data  source  is   as  simple  as  having  your  class   implemenQng  IEnumerable<T>    
  • 31. LINQ  Clauses   from     let   where   join   select   orderby   group  
  • 32. Structure  of  LINQ  Queries   First  Line   • from  clause   Middle  Lines   • from,  where,  orderby,  join,  let  clauses   Last  Line   • select  or  group-by  clause  
  • 33. LINQ  Architecture   Visual Basic C# Others… .NET Language-Integrated Query LINQ to ADO.NET LINQ LINQ LINQ LINQ LINQ to XML to Object to SQL to DataSet to Entities <book>          <Qtle/>          <author/>          <year/>          <price/>   </book>   Objects   RelaQonal  DB   XML  
  • 34. IEnumerable<T>   from  itemName  in  srcExpr   Object   where  predExpr   Object   orderby  (keyExpr  (ascending  |  descending))   Object   Objects  in   Memory   select  selExpr   ...   where   where   orderby   where   orderby   select  
  • 35.   IQueryable<T>   Nothing     In     from  itemName  in  srcExpr   where  predExpr   orderby  (keyExpr  (ascending  |  descending))   Memory   select  selExpr   ...   “FROM  [srcExpr]  WHERE  ...”   where   FROM  [srcExpr]  WHERE  predExpr   where   ORDER  BY  [keyExpr]”   orderby   SELECT  [selExpr]   where   FROM  [srcExpr]  WHERE  predExpr   ORDER  BY  [keyExpr]”   orderby   select  
  • 36. Deferred  vs.  Non-­‐deferred  Operators   Deferred   Non-­‐deferred   •  Rule  of  thumb:  LINQ  query  syntax     •  Rule  of  thumb:  scalar/single-­‐value   or  IEnumerable<T>  return   return  or  conversion   •  AsEnumerable, Cast, •  Aggregate, All, Any, Concat, DefaultIfEmpty, Average, Contains, Count, Distinct, Empty, Except, ElementAt, GroupBy, GroupJoin, ElementAtOrDefault, Last, Intersect, Join, OfType, LastOrDefault, LongCount, OrderBy, Max, Min, Single, OrderByDescending, Range, SingleOrDefault, Sum, Repeat, Reverse, Select, ToArray, ToDictionary, SelectMany, Skip, ToList, ToLookup SkipWhile, Take, TakeWhile, ThenBy, ThenByDescending, Union, Where 36  
  • 38. Features  Covered   •  OpQonal  Parameters   •  Named  Arguments   •  Beeer  COM  Interop   •  Generic  Variance   •  Robust  Locking   •  Field-­‐like  Events  
  • 40. How  to  implement  MailMessage()?  
  • 43. OpQonal  Values   •  Numeric  and  string  literals   •  null   •  Compile-­‐Qme  constants   •  Enum  members   •  default(T)   •  Parameterless  constructor  for  structs  
  • 44. RestricQons   •  OpQonal  parameters  must  come  a6er   required  parameters   –  Except  for  parameter  array  (empty  array  is  used   when  not  specified)   •  OpQonal  parameters  can’t  be  ref  or  out  
  • 46. In  Depth:  Call  Site  
  • 47. Consequence   •  OpQonal  values  are  part  of  the  published  API,   if  they  are  changed,  client  code  must  be   recompiled.    Worse,  the  compiler  won’t  warn   you  if  you  don’t  change.  
  • 49. How  to  Avoid  the  Comments?  
  • 53. RestricQons   •  PosiQonal  arguments  must  come  before   named  arguments  
  • 54. Under  the  Hood   •  The  compiler  just  reorders,  that’s  all  
  • 55. Consequence   •  Parameter  names  are  part  of  the  published   API,  if  they  are  changed,  client  code  must  be   changed.  
  • 57. How  Do  You  Like  This?  
  • 63. Generic  Covariance   •  Generic  covariance  reserves  assignment   compaQbility  on  generic  types   –  If  T1  is  a  subtype  of  T2,  GT<T1>  behaves  like   subtype  of  GT<T2>  on  assignment   •  Safe  only  when  GT  doesn’t  “take  in”  any  T  
  • 68. Generic  Contravariance   •  Generic  covariance  reverses  assignment   compaQbility  on  generic  types   –  If  T1  is  a  subtype  of  T2,  GT<T1>  behaves  like   supertype  of  GT<T2>  on  assignment   •  Safe  only  when  GT  doesn’t  return  any  T  
  • 73. Problem   If  the  thread  is  aborted  a>er  the  lock  is  acquired  but  before  we  enter   the  try  block,  we  won’t  have  released  the  lock.  
  • 76. The  Problem   Lock  on  ‘this’  is  bad.    Lock  on  ‘type’  is  bad.  
  • 77. The  SoluQon   A  simple  lock  would  work,  but  this  is  beeer  because  it’s  lock-­‐free.  
  • 79. WHAT  IS  DYNAMIC  BINDING  
  • 80. StaQc  vs.  Dynamic  Binding   Sta2c  Binding   Dynamic  Biding   •  Compiler  figures  out  which   •  All  bindings  happen  during   members  to  call  (binding   run  Qme   process)   –  Defer  subtype  polymorphic   resoluQon  Qll  run  Qme  
  • 82. Benefits  of  StaQc  Binding   •  Type  and  name  errors  are  detected  at  compile   Qme,  e.g.   –  Invoke  non-­‐existent  members   –  Pass  in  arguments  with  wrong  type   –  Perform  illegal  cast  
  • 84. HOW  IS  IT  IMPLEMENTED?  
  • 85. Run  Time  Binding   •  Instead  of  aeempQng  binding  and  generaQng   CIL,  the  compiler  packages  the  call  and  sends   it  to  the  Dynamic  Language  RunQme     •  At  run  Qme,  the  DLR  performs  binding  and   execuQon  
  • 86. Under  the  Hood   becomes  
  • 88. Process  in  a  nutshell   C#   dynamic   Dynamic   builds   Objects   User-­‐defined  or  from  other  languages   compiled   uses   IDynamicMetaObjectProvider   Call  Sites   cached   Delegate   Expression   emits   Tree   DLR   C#  Binder   builds  
  • 90. WHEN  DO  WE  NEED  IT?  
  • 91. Key  Scenarios   1.  Access  a  member  with  only  knowledge  of  its   name,  arguments,  and  target  object   2.  Interop  with  dynamic  languages,  e.g.   IronRuby,  IronPython   3.  Have  the  target  object  decide  how  to   respond  to  a  call  at  run  Qme  
  • 92. Key  Scenarios   1.  Access  a  member  with  only  knowledge  of  its   name,  arguments,  and  target  object   2.  Interop  with  dynamic  languages,  e.g.   IronRuby,  IronPython   3.  Have  the  target  object  decide  how  to   respond  to  a  call  at  run  Qme  
  • 96. Single  vs.  MulQple  Dispatch   Single  Dispatch   Mul2ple  Dispatch   •  Method  is  selected  based   •  Method  is  selected  based   on  the  runQme  type  of  the   on  both  the  runQme  type  of   target  object   the  target  object  and  those   of  the  method’s  arguments  
  • 98. Key  Scenarios   1.  Access  a  member  with  only  knowledge  of  its   name,  arguments,  and  target  object   2.  Interop  with  dynamic  languages,  e.g.   IronRuby,  IronPython   3.  Have  the  target  object  decide  how  to   respond  to  a  call  at  run  Qme  
  • 100. Work  with  Ruby  Class  
  • 102. Key  Scenarios   1.  Access  a  member  with  only  knowledge  of  its   name,  arguments,  and  target  object   2.  Interop  with  dynamic  languages,  e.g.   IronRuby,  IronPython   3.  Have  the  target  object  decide  how  to   respond  to  a  call  at  run  Qme  
  • 103. The  Magic  Interface   IDynamicMetaObjectProvider   ExpandoObject   DynamicObject  
  • 105. DynamicObject’s  OperaQons   Name   Descrip2on   TryGetMember   Member  geeer,  e.g.  obj.Name   TrySetMember   Member  seeer,  e.g.  obj.age  =  10   TryDeleteMember   Member  removal  (no  equivalent  in  C#)   TryInvokeMember   Method  invocaQon,  e.g.  obj.Invoke()   TryConvert   CasQng,  e.g.  (int)obj   TryCreateInstance   Object  creaQon  (no  equivalent  in  C#)   TryInvoke   Self  invocaQon,  e.g.  obj(10)   TryBinaryOperaQon   Binary  operaQon,  e.g.  obj  +  10   TryUnaryOperaQon   Unary  operaQon,  e.g.  !obj   TryGetIndex   Indexer  geeer,  e.g.  obj[“key”]   TrySetIndex   Indexer  seeer,  e.g.  obj[“key”]  =  value   TryDeleteIndex   Indexer  removal  (no  equivalent  in  C#)  
  • 106. Log  Seeers  &  InvocaQons  
  • 109. Close  to  the  metal  
  • 110. …Close  to  the  metal  
  • 111. …Close  to  the  metal  
  • 113. RestricQon  #1   •  Doesn’t  work  with  extension  methods  
  • 114. RestricQon  #2   •  Can’t  resolve  staQc  members  or  constructors   on  a  dynamic  type  
  • 115. RestricQon  #3   •  Method  groups,  anonymous  methods  and  lambda   expressions  to  be  casted  to  exact  type