2.3 Cool features in C# academy.zariba.com 1. Lecture Content 1.Extension Methods 2.Anonymous Types 3.Delegates 4.Action and Func 5.Events 6.Lambda Expressions.

Slides:



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

LINQ and Collections An introduction to LINQ and Collections.
Extension Methods, Anonymous Types LINQ Query Keywords, Lambda Expressions Svetlin Nakov Telerik Corporation
C# and LINQ Yuan Yu Microsoft Research Silicon Valley.
Doncho Minkov Telerik School Academy schoolacademy.telerik.com Technical Trainer
Meeting #1 – November 2010 – Intro to C# Homework Assignments Svetlin Nakov Telerik Corporation
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 8 Arrays.
Arrays. A group of data with same type stored under one variable. It is assumed that elements in that group are ordered in series. In C# language arrays.
1.9 Methods academy.zariba.com 1. Lecture Content 1.What is a method? Why use methods? 2.Void Methods and methods with parameters 3.Methods which return.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
1.10 Strings academy.zariba.com 1. Lecture Content 1.What is a string? 2.Creating and Using strings 3.Manipulating Strings 4.Other String Operations 5.Building.
A tour of new features introducing LINQ. Agenda of LINQ Presentation We have features for every step of the way LINQ Fundamentals Anonymous Functions/Lambda.
C# Event Processing Model Solving The Mystery. Agenda Introduction C# Event Processing Macro View Required Components Role of Each Component How To Create.
XML files (with LINQ). Introduction to LINQ ( Language Integrated Query ) C#’s new LINQ capabilities allow you to write query expressions that retrieve.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
Understanding Events and Exceptions Lesson 3. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understand events and event handling Understand.
Chapter 3 Single-Table Queries
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Lambdas and Streams. Functional interfaces Functional interfaces are also known as single abstract method (SAM) interfaces. Package java.util.function.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Extension Methods, Anonymous Types LINQ Query Keywords, Lambda Expressions Based on material from Telerik Corporation.
Arrays Chapter 7. 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores : Inspecting.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Hoang Anh Viet Hà Nội University of Technology Chapter 1. Introduction to C# Programming.
 Although VERY commonly used, arrays have limited capabilities  A List is similar to an array but provides additional functionality, such as dynamic.
Introduction to LINQ Chapter 11. Introduction Large amounts of data are often stored in a database—an organized collection of data. A database management.
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
Object Oriented Programming Generic Collections and LINQ Dr. Mike Spann
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 10 th Lecture Pavel Ježek
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections UTPA – Fall 2011.
Introduction to Object-Oriented Programming Lesson 2.
Variables 1. What is a variable? Something whose value can change over time This value can change more than once over the time period (no limit!) Example:
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
CIS 200 Test 01 Review. Built-In Types Properties  Exposed “Variables” or accessible values of an object  Can have access controlled via scope modifiers.
IAP C# 2011 Lecture 2: Delegates, Lambdas, LINQ Geza Kovacs.
Arrays Chapter 7. 2 Declaring and Creating Arrays Recall that an array is a collection of elements all of the _____________ Array objects in Java must.
LINQ and Lambda Expressions Telerik Software Academy LINQ Overview.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
Chapter 11.  Large amounts of data are often stored in a database—an organized collection of data.  A database management system (DBMS) provides mechanisms.
Functional Processing of Collections (Advanced) 6.0.
Lists/Dictionaries. What we are covering Data structure basics Lists Dictionaries Json.
Functional Programming Data Aggregation and Nested Queries Ivan Yonkov Technical Trainer Software University
Windows Programming Lecture 03. Pointers and Arrays.
Building Web Applications with Microsoft ASP
Lecture 10 Collections Richard Gesick.
Arrays Chapter 7.
Introduction to LINQ and Generic Collections
CIS 200 Test 01 Review.
Visual Basic 2010 How to Program
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Arrays, For loop While loop Do while loop
C# Event Processing Model
6 Delegate and Lambda Expressions
Introduction to LINQ Chapter 11 10/28/2015 Lect 4 CT1411.
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections
Exception Handling Chapter 9 Edited by JJ.
Introduction to LINQ Chapter 11.
Lesson 7. Events, Delegates, Generics.
Arrays Chapter 7.
LINQ - 2 Ravi Kumar C++/C# Team.
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
Advanced .NET Programming I 6th Lecture
Chengyu Sun California State University, Los Angeles
CS4540 Special Topics in Web Development LINQ to Objects
Presentation transcript:

2.3 Cool features in C# academy.zariba.com 1

Lecture Content 1.Extension Methods 2.Anonymous Types 3.Delegates 4.Action and Func 5.Events 6.Lambda Expressions 7.LINQ 2

1. Extension Methods 3 Once a class is defined and compiled into an assembly its definition is final – the only way to update the code is to recode and recompile Extension methods allow existing compiled types to gain new functionality without recompilation or changing the original assembly

2. Anonymous Types 4 Anonymous types are used to encapsulate a set of read-only properties into a single object Used if there is no need for a separate class The data is going to be used once and then discarded or never used again

3. Delegates 5 Delegates are special.NET types that hold a method reference They describe the signature of a given method Their values are methods Delegates are reference types They are roughly similar to function pointers in other languages Can point to a sequence of multiple methods

4. Actions and Func 6 Action and Func are simplified delegates Action only defines a delegate with return type void with a given set of parameters – T1,T2,T3... Func only defines a delegate with return type(K) and a given set of parameters (T1,T2,T3) Predicate is a Func which returns a boolean

5. Events 7 An Event is a message sent by an object to signal the occurrence of an action Enable a class or object to notify other classes or objects when something interesting occurs Publisher (the class that sends) raises the event Subscribers (the class that receives) handle the event

6. Lambda Expressions 8 A lambda expression is an anonymous function It uses the lambda operator => (reads as “go to”) The LHS specifies the parameters The RHS specifies the expression or statement

7. LINQ 9 LINQ is a set of extensions to.NET Framework Keywords: From – specifies data source and range of variables Where – filters the source of elements Select – specifies the type and shape that the elements are returned in Group – groups results according to a key value OrderBy – sorts in ascending or descending order

7. LINQ with Lambda 10 Keywords: Where – searches by a given condition First/FirstOrDefault – gets the first matched element Last/LastOrDefaut – guess what that does Select/Cast – makes a projection/conversion to another type OrderBy/ThenBy/+Descending – sorts a collection Any – checks if any element matches a condition All – checks if all elements match a condition ToArray/ToList/AsEnumerable Reverse

7. LINQ with Lambda 11 Keywords: Average – calculates the average Count – counts the elements Max – Determines the maximum value Sum – sums the values in a collection

Homework Implement an extension method Substring(int index, int length) for the StringBuilder. Test your application. 2. Implement a set of extension method for IEnumerable - sum, product, min, max, average 3. Create a class Student with properties FirstName, LastName, Age, Faculty number, Phone, , marks (a list) and group number. Create a sample list of students. Do the below exercises with the list. Write a method that from a given array of students finds all students whose first name is before its last name alphabetically. Use LINQ query operators. Write a LINQ query that finds the first and last name of all students with age between 18 and 24. Sort a list of students by first name and then by last name using lambda. Select all students from group 2 and sort them by first name. Extract all students who have s in abv.bg Extract all students with phones in Sofia Extract students that have at least one mark Excellent 6 into a new anonymous class that has properties FullName and Marks Extract all students who have exactly two marks “2”.

Homework Given an array of numbers, list all numbers that are divisible by 7 and 3. Use lambda. 5. Using delegates write a class Timer that can execute certain method at each t seconds. 6. Rewrite the above class using events. 7. Write a program to return the string with maximum length from an array of strings.

14 References

15 Zariba Academy Questions