Tech·Ed North America /18/2018 2:05 PM

Slides:



Advertisements
Similar presentations
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Advertisements

MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Feature: Web Client Keyboard Shortcuts © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Feature: Assign an Item to Multiple Sites © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Robert LevyDoug Kramer Program ManagerDevelopment Lead DTL337.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.

Dmitry Sotnikov New Product Research Manager Quest Software DTL404.
customer.
Mickey Gousset Senior Technical Developer Infront Consulting Group Session Code: DTL330.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
demo Demo.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
Feature: Suggested Item Enhancements – Analysis and Assignment © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and.
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
Jonathan Aneja Program Manager Microsoft Corporation Session Code: DTL336 Anders Hejlsberg Technical Fellow Microsoft Corporation.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.

Mark Michaelis Chief Computer Nerd IDesign/Itron/IntelliTechture DTL313.
MIX 09 4/17/2018 4:41 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
How We Do Language Design at Microsoft (C#, Visual Basic, F#)
Tech·Ed North America /5/2018 6:10 PM
6/12/ :53 PM DEV311 Deep Dive into Microsoft Visual Studio Team Foundation Server 2010 Reporting Steven Borg, Principal ALM Consultant Northwest.
Tech·Ed North America /19/2018 3:29 PM
6/26/2018 9:02 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Upgrading Your C# Programming Skills to Be a More Effective Developer
Tech·Ed North America /7/2018 2:58 PM
9/11/2018 5:53 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Tech·Ed North America /14/2018 7:13 PM
Возможности Excel 2010, о которых следует знать
Sysinternals Tutorials
Tech·Ed North America /19/ :44 PM
Title of Presentation 11/22/2018 3:34 PM
11/22/2018 8:05 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Jason Zander Unplugged
Title of Presentation 12/2/2018 3:48 PM
Brian Keller Sr. Technical Evangelist Microsoft Session Code: DEV310
12/5/2018 3:24 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Tech·Ed North America /17/2019 1:47 AM
Tech·Ed North America /17/2019 6:01 PM
Brian Keller Sr. Technical Evangelist Microsoft Session Code: DEV310
Building Silverlight Apps with RIA Services
Tech Ed North America /12/2019 6:45 AM Required Slide
Silverlight Debugging
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
A Lap Around Internet Explorer 9 For Developers
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
2010 Microsoft BI Conference
Tech·Ed North America /25/ :53 PM
Hack-proofing your Clients using Windows 7 Security!
How and When to Use MEF: Too Much Is Never Enough
PENSACOLA ENERGY WORK PLAN OCTOBER 10, 2016
Title of Presentation 5/12/ :53 PM
Шитманов Дархан Қаражанұлы Тарих пәнінің
Lap Around the Windows Azure Platform
Code First Development in Microsoft ADO.NET Entity Framework 4.1
Building BI applications using PowerPivot for Excel
Title of Presentation 5/24/2019 1:26 PM
7/5/2019 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
Tech·Ed North America /6/2019 7:10 PM
Title of Presentation 7/24/2019 8:53 PM
Tech·Ed North America /17/2019 4:14 PM
What’s New in Visual Studio 2012 for Web Developers
Presentation transcript:

Tech·Ed North America 2009 5/18/2018 2:05 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Getting the Most from Lambda Expressions Tech·Ed  North America 2009 5/18/2018 2:05 PM Getting the Most from Lambda Expressions Deborah Kurata President InStep Technologies, Inc Session Code: DTL315 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Deborah Kurata is... Consultant and President of: InStep Technologies, Inc. Author of: Doing Objects in VB 2005 Best Kept Secrets in .NET Software designer/developer INETA Speaker Microsoft MVP DeborahK@insteptech.com

InStep Technologies is... Consulting Mentoring services to get you started and keep you going with .NET Strategic software consulting and training services Application architecture and design Custom software development of Windows and Web-based applications Web site: www.insteptech.com

You Are... Using Generic Lists Using Lambda Expressions List(Of Customer) List<Customer> Using Lambda Expressions Just getting started/new to them Use them once in a while Use them everyday

This Presentation is … Fun with Lambda Expressions What are Lambda Expressions? Lambdas as Generic Delegates Lambdas as Callable Entities Lambdas as Callbacks

Generic Lists Class Customer Class Customers Manages a single customer Customer properties Customer methods Class Customers Manages the list of customers List(Of Customer) List<Customer>

Fun With Lambda Expressions 5/18/2018 2:05 PM demo Fun With Lambda Expressions © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Lambda Calculus “Formal system designed to investigate function definition, function application, and recursion.” Wikipedia

What are Lambda Expressions? New in Visual Basic 9 and C# 3.0 (VS 2008) Unnamed, inline functions Single statement Multiple statement (C# only; coming in VB 10) Used wherever delegates are required

What is a Delegate? An object that holds a reference to a method with a particular parameter list and return type Like object-oriented, type-safe function pointer Make it possible to treat methods as entities Assign to variables Pass as parameters

Classic Delegate Example: Events // Passes the method to the new delegate HelloButton.Click += new EventHandler(HelloButton_Click); ' AddressOf assigns the address of the ' method to the delegate AddHandler HelloButton.Click, _ AddressOf HelloButton_Click

Using Lambda Expressions // C# HelloButton.Click += (s, ev) => MessageBox.Show("Hello World"); ' VB: AddHandler HelloButton.Click, _ Function(s, ev) _ MessageBox.Show("Hello World")

Defining Delegates Named method Anonymous method (C# 2.0) Lambda expression (C# 3.0 and VB 9)

Lambda Expression Syntax - VB ' General syntax: Dim foundCustomer as Customer = _ allCust.First(Function(c as Customer) _ c.CustomerId = 4) ' With inferred typing: Dim foundCustomer = _ allCust.First(Function(c) _

Lambda Expression Syntax – C# ' General syntax: Customer foundCustomer = allCust.First((Customer c) => c.CustomerId == 4); ' With inferred typing: var foundCustomer = allCust.First(c =>

Lambda Multiline Syntax – C# var foundCustomer = allCust.First(c => { Debug.WriteLine(c.FullName); if (c.CustomerId == 4) return true; else return false; });

Features that Use Delegates Event handlers Enumerable class methods Extension methods of IEnumerable(T) Examples: Aggregate, All, Any, FirstOrDefault LINQ methods Used by LINQ Examples: OrderBy, Where, GroupBy

Lambdas as Generic Delegates Generic delegates were new in .NET 2.0 Predicate Delegates Action Delegates Func Delegates

Predicate Delegate Predicate: “An operator or function which returns a Boolean value” - Wikipedia Encapsulates a method that evaluates to True or False Takes one parameter

Example: Predicate Delegate ' VB: Dim foundCustomer = _ Array.Find(custArray, Function(c) _ c.LastName.StartsWith("K")) // C#: var foundCustomer = Array.Find(custArray, c => c.LastName.StartsWith("K"));

demo Predicate Delegates 5/18/2018 2:05 PM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Action Delegate Encapsulates a method that does not return a value Sub in VB void in C# Takes up to four parameters

Example: Action Delegate ' VB: Can only use named methods allCust.ForEach(AddressOf WriteToDebug) // C#: allCust.ForEach(c => Debug.WriteLine(c.FullName));

demo Action Delegates 5/18/2018 2:05 PM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Func Delegate Encapsulates a method that returns a value Takes up to 4 parameters and a return value Last parameter is the return value Func<int, int, string> Func(Of Integer, Integer, String)

Example: Func Delegate ' VB: Dim total = allCust.Sum(Function(c) _ c.SalesTotal) // C#: var total = allCust.Sum(c => c.SalesTotal);

demo Func Delegates 5/18/2018 2:05 PM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Lambdas as Callable Entities Lambda expressions can be assigned to a delegate variable Lambda expression is executed when the delegate is executed

Example: Assignment ' VB: Infers the type Dim f = _ Function(x as Integer) (x + x).ToString() Debug.WriteLine(f(5)) Debug.WriteLine(f(10)) // C#: Func<int,string> f = x => (x + x).ToString(); Debug.WriteLine(f(5)); Debug.WriteLine(f(10));

Lambda Expression Execution Lambda expressions are executed when they are called, not when they are constructed Local variables used in a lambda expression are “captured” or “lifted” Variable value used is the value at execution time Variable lifetime extends to the lifetime of the delegate

Example: Local Variables int y = 0; Func<int,string> f = x => (x + y).ToString(); y = 10; Debug.WriteLine(f(5)); ' VB: Dim y As Integer = 0 Dim f As Func(Of Integer, String) = _ Function(x) (x + y).ToString() y = 10 Debug.WriteLine(f(5))

demo Callable Entities 5/18/2018 2:05 PM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Lambdas as Callbacks Callback Passes a function to a function “Executable code that is passed as an argument to other code” Passes a function to a function A delegate does not know or care about the class of the method it is referencing No need to reference the class that defined the method

5/18/2018 2:05 PM demo Callbacks © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Getting the Most from Lambdas Use Lambda expressions for Writing inline functions Calling LINQ methods Calling extension methods that take a delegate Creating callable functions Performing callbacks

Resources www.microsoft.com/teched www.microsoft.com/learning Sessions On-Demand & Community www.microsoft.com/learning Microsoft Certification & Training Resources http://microsoft.com/technet Resources for IT Professionals http://microsoft.com/msdn Resources for Developers www.microsoft.com/learning Microsoft Certification and Training Resources

Related Content DTL336 Future Directions for Visual Basic Presenter(s): Jonathan Aneja, Anders Hejlsberg DTL402 How LINQ Works: A Deep Dive into the Microsoft Visual Basic and C# Implementations Presenter: Jonathan Aneja

Track Resources Visit the DPR TLC for a chance to win a copy of Visual Studio Team Suite. Daily drawing occurs every day in the TLC at 4:15pm. Stop by for a raffle ticket http://www.microsoft.com/visualstudio http://www.microsoft.com/visualstudio/en-us/products/teamsystem/default.mspx Please visit us in the TLC blue area

Complete an evaluation on CommNet and enter to win!

5/18/2018 2:05 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.