© Copyright SELA software & Education Labs Ltd. 14-18 Baruch Hirsch St.Bnei Brak 51202 Israel www.sela.co.il 1 בס " ד.

Slides:



Advertisements
Similar presentations
The Microsoft Technical Roadshow 2007 Language Enhancements and LINQ Daniel Moth Developer & Platform Group Microsoft Ltd
Advertisements

Introduction to Web Application
Dynamic internals. Introductions  Alexandru Ghiondea  C# Compiler QA  
 Anders Hejlsberg Technical Fellow Microsoft Corporation TL16.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 th Lecture Pavel Ježek.
C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
1 Generic Collections Chapter Objectives You will be able to Use generic collection classes available in the.NET framework.
Static Members, Structures, Enumerations, Generic Classes, Namespaces Learning & Development Team Telerik Software Academy.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Delegates and Events.
Ken Casada Developer Evangelist Microsoft Switzerland
.NET 3.5 – Mysteries. NetFx Evolution NetFx 1.0 C# 1.0, VB 7.0, VS.NET NetFx 1.1 C# 1.1, VB 7.1, VS 2003 NetFx 2.0 C# 2.0, VB 8.0, VS 2005 NetFx 3.0 C#
Visual Studio 2010 and.NET Framework 4 Training Workshop.
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
What’s New in C# 4.0? Pavel Yosifovich SELA Group
Inheritance and Polymorphism CS351 – Programming Paradigms.
GTECH 731 Lab Session 2 Lab 1 Review, Lab 2 Intro 9/6/10 Lab 1 Review Lab 2 Overview.
Louis de Klerk Consultant Inobits Consulting DTL308.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
C# Tutorial From C++ to C#. Some useful links Msdn C# us/library/kx37x362.aspxhttp://msdn.microsoft.com/en- us/library/kx37x362.aspx.
Saravanan.G.
Introduction to Classes SWE 344 Internet Protocols & Client Server Programming.
BIM313 – Advanced Programming Techniques Object-Oriented Programming 1.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Topics Scope Scope and Lifetime Referencing Environments.
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
© FPT Software Advanced features in C# 1. © FPT Software Agenda Attributes Delegates & Events Anonymous Types & Dynamic Type Extension Methods Lambda.
Features of Object Oriented Programming:  A class is a collection of things which posses common similarities.  In C#.NET a class is a user defined.
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
Applied Computing Technology Laboratory QuickStart C# Learning to Program in C# Amy Roberge & John Linehan November 7, 2005.
Hoang Anh Viet Hà Nội University of Technology Chapter 1. Introduction to C# Programming.
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
Object Oriented Programming Generic Collections and LINQ Dr. Mike Spann
Class and Structure. 2 Structure Declare using the keyword struct purpose is to group data Default visibility mode is public A struct doesn't have a constructor.
Static. 2 Objectives Introduce static keyword –examine syntax –describe common uses.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 10 th Lecture Pavel Ježek
Recitation 8 User Defined Classes Part 2. Class vs. Instance methods Compare the Math and String class methods that we have used: – Math.pow(2,3); – str.charAt(4);
Introduction to C# 2.0 An Advanced Look Adam Calderon Principal Engineer - Interknowlogy Microsoft MVP – C#
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Microsoft.NET Вторая лекция. Reference and value types public class RefType { } public struct ValueType : IDisposable { public int A, B; public ValueType(int.
Generics Generics vs. heterogeneous collections Doing your own generics FEN 2014UCN Teknologi/act2learn1.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Satisfy Your Technical Curiosity C# 3.0 Raj Pai Group Program Manager Microsoft Corporation
Java Programming Final Keyword In Java. final keyword The final keyword in java is used to restrict the user. The final keyword can be used in many context.
IAP C# 2011 Lecture 2: Delegates, Lambdas, LINQ Geza Kovacs.
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
Jonathan Aneja Program Manager Microsoft Corporation Session Code: DTL336 Anders Hejlsberg Technical Fellow Microsoft Corporation.
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
Subtying Kangwon National University 임현승 Programming Languages These slides were originally created by Prof. Sungwoo Park at POSTECH.
Luke Hoban Senior Program Manager Microsoft Session Code: DTL310.
Введение в DLR UNETA 16 апреля, 2010 Иван Колодяжный, Software Developer Teamdev Ltd.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Module 5: Programming with C#. Overview Using Arrays Using Collections Using Interfaces Using Exception Handling Using Delegates and Events.
Visual Studio 2010 and.NET Framework 4 Training Workshop.
Modern Programming Tools And Techniques-I
/* LIFE RUNS ON CODE*/ Konstantinos Pantos Microsoft MVP ASP.NET
using System; namespace Demo01 { class Program
Interface.
Internet and Java Foundations, Programming and Practice
Chapter 5: Programming with C#
New Features of C# Kuppurasu Nagaraj Microsoft Connect 2016
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Tech·Ed North America /18/2018 5:14 PM
Conditional Statements
class PrintOnetoTen { public static void main(String args[]) {
The important features of OOP related to C#:
Module 2 Variables, Assignment, and Data Types
Advanced .NET Programming I 3rd Lecture
Advanced .NET Programming I 6th Lecture
Presentation transcript:

© Copyright SELA software & Education Labs Ltd Baruch Hirsch St.Bnei Brak Israel 1 בס " ד

2 Dynamic lookup Named and optional parameters COM-specific interop features Variance

3 Dynamic objects are declared using the “dynamic” keyword When declaring a type as Dynamic there is no design time type checking And certainly no IntelliSence … Missing properties or methods will cause an exception at run time Calling a method on a dynamic object will always return a dynamic object The object can be a.NET object, a COM object, or even an html object

4 dynamic id = ; dynamic name = "Miki Mouse"; dynamic students = new List () { "yossi", "dana", “noam" }; Console.WriteLine(++age); students.Add("shara"); foreach (dynamic item in students ) { Console.WriteLine(item); }

5 The dynamic keyword is NOT like the var keyword var is resolved as design time dynamic is only resolved at runtime var x = 10; x = "name"; dynamic y = 10; y = "name";

6 public static int Sum(params int[] values) { int sum = 0; for (int i = 0; i < values.Length; i++) { sum += values[i]; } return sum; } public static double Sum(params double[] values) { double sum = 0; for (int i = 0; i < values.Length; i++) { sum += values[i]; } return sum; }

7 public static dynamic Sum(params dynamic[] values) { dynamic sum = values[0]; for (int i = 1; i < values.Length; i++) { sum += values[i]; } return sum; } Console.WriteLine(Sum(2, 3, 4)); Console.WriteLine(Sum("a", "b", "c")); Console.WriteLine(Sum(DateTime.Now, new TimeSpan(3, 3, 3)));

8

9 Python Binder Ruby Binder COM Binder JavaScript Binder Object Binder Dynamic Language Runtime Expression Trees Dynamic Dispatch Call Site Caching IronPythonIronPythonIronRubyIronRubyC#C#VB.NETVB.NETOthers…Others…

10 static void Main(string[] args) { int i = 10; object o = new object(); dynamic i1 = i; dynamic o1 = o; }

11

12

13

14 namespace Microsoft.CSharp.RuntimeBinder { public class CSharpSetMemberBinder { } namespace ProxyBinder { public class ProxyCSharpSetMemberBinder : CSharpSetMemberBinder { } } namespace Microsoft.CSharp.RuntimeBinder { public class CSharpSetMemberBinder : ProxyCSharpSetMemberBinder { } }

15 Access to members is limited by Accessibility level (no access to private members) No access to static members or extension methods

16 public static class Math { public static decimal Abs(decimal value); public static double Abs(double value); public static float Abs(float value); public static int Abs(int value); public static long Abs(long value); public static sbyte Abs(sbyte value); public static short Abs(short value); } public class Persons { public void Add(string name, int id, float age); public void Add(string name, int id); public void Add(string name); }

17 Default value can be a Constant, null or default Ctor of Struct Must (officially) appear after all required parameters static void Add(int id, string name = "", float age = 0) { }

18

19 static void Add(int id, string name = "", float age = 0) {} static void Add(int id, [Optional, DefaultParameterValue("")] string name, [Optional, DefaultParameterValue(0)] float age) {} static void Add(DateTime dt1 = new DateTime(), DateTime dt2 = default(DateTime)) {} static void Add([Optional]DateTime dt1, [Optional]DateTime td2) {}

20

21 static void Main(string[] args) { Add(); } static void Add(string name = "shlomo") { }

22 static void Main(string[] args) { Add("shlomo"); } static void Add( [Optional, DefaultParameterValue("shlomo")] string name) { }

23 static void Add(int id, string name = "shlomo", float age = 0) { } static void Main() { Add(22,, 24); } static void Main() { Add(22, age: 24); }

24 Advantages: – Named parameters can be used even for non-optional parameters – It can makes the method call clearer Disadvantages: – You cannot change the names of parameters in public methods – The order of sent parameters can change the result

25

26 Covariance: delegate object CovarianceDelegate(); static Person CovarianceMethod(){ } CovarianceDelegate cd = CovarianceMethod; Contravariance: delegate void ContravarianceDelegate(Person obj); static void ContravarianceMethod(object obj) ContravarianceDelegate cva = ContravarianceMethod;

27 void PrintAllItems(List list) { foreach (var item in list) { Console.WriteLine(item); } void f() { List list = new List () { "name", "abcde", "1234" }; PrintAllItems(list); } void PrintAllItems(IEnumerable list)

28 class Person : IComparer { public int Compare(Person x, Person y) { } } class Employee : Person { } IComparer comparer = new Person();

29 static Action GetAction() { } Action action = GetAction();

30 public interface IEnumerable : IEnumerable { IEnumerator GetEnumerator(); } public interface IComparer { int Compare(T x, T y); } public delegate void Action (T obj);

31 My Blog (in Hebrew) C# 4.0 Post Collection 2/c-4-0-table-of-content.aspx PDC 2008 : Future of C# session.

© Copyright SELA software & Education Labs Ltd Baruch Hirsch St.Bnei Brak Israel 32