.NET and .NET Core9. Towards Higher Order2017
.NET and .NET Core 9. Towards Higher Order 2017
Topics1.TowardsHigher Order:Expressiveness2. Towards Higher Order:Enhanced Dynamics3.Towards Higher Order: Compiling As Services4.Covarianceand ContravarianceReferences :CommonTypeSystem(MsDN).NETFrameworkClassLibraryOverview(MSDN)Inheritance(C#ProgrammingGuide)(MSDN)Polymorphism(C#Programming Guide)(MsDN)
Topics 1. Towards Higher Order: Expressiveness 2. Towards Higher Order: Enhanced Dynamics 3. Towards Higher Order: Compiling As Services 4. Covariance and Contravariance References: Common Type System(MSDN) .NET Framework Class Library Overview (MSDN) Inheritance (C# Programming Guide) (MSDN) Polymorphism (C# Programming Guide) (MSDN)
3. Towards higher order: Expressiveness·Iterators·Lambda Expression·Generic: LINQExtension method·EffectiveCoding
3. Towards higher order: Expressiveness • Iterators • Lambda Expression • Generic • LINQ • Extension method • Effective Coding
Iterators·Aniteratormethodorgetaccessorperforms acustom iterationoveracollection.: An iterator method uses the yield return (C#) statement to returneachelementoneatatime..When a yield return statement is reached, the current location incodeisremembered.Execution is restarted fromthat locationthe next time the iteratorfunctioniscalled
Iterators • An iterator method or get accessor performs a custom iteration over a collection. • An iterator method uses the yield return (C#) statement to return each element one at a time. • When a yield return statement is reached, the current location in code is remembered. • Execution is restarted from that location the next time the iterator function is called
public class Appstatic void MainO中DaysOfTheWeekdays=newDaysOfTheWeekOforeach(string dayindays)Console.Write(day +"");Console.ReadKeyO:1子public class DaysOfTheWeek :IEnumerableprivate string[J days ={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"]public IEnumerator GetEnumeratorOfor (int index = O: index < days.Length; index++)yield return days[indexl;1公