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.

Slides:



Advertisements
Similar presentations
Extension Methods, Anonymous Types LINQ Query Keywords, Lambda Expressions Svetlin Nakov Telerik Corporation
Advertisements

©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 6: Lists, Tuples, and Dictionaries – Exercises Xiang Lian The University of Texas – Pan American Edinburg,
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.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
XML files (with LINQ). Introduction to LINQ ( Language Integrated Query ) C#’s new LINQ capabilities allow you to write query expressions that retrieve.
The University of Texas – Pan American
Neal Stublen How does XMLReader work?  XmlReader.Read() Advances to next node XmlReader properties access node name, value, attributes,
 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.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX.
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections UTPA – Fall 2011.
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg,
LINQ Language Integrated Query LINQ1. LINQ: Why and what? Problem Many data sources: Relational databases, XML, in-memory data structures, objects, etc.
CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 11.  Large amounts of data are often stored in a database—an organized collection of data.  A database management system (DBMS) provides mechanisms.
Introduction to programming in java Lecture 21 Arrays – Part 1.
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Introduction to LINQ and Generic Collections
Computer Programming BCT 1113
PL/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-1
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
The University of Texas – Pan American
The University of Texas – Pan American
CSCI 3327 Visual Basic Chapter 7: Data Manipulation in Arrays
Arrays An Array is an ordered collection of variables
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
The University of Texas Rio Grande Valley
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I UTPA – Fall 2012 This set of slides is revised from lecture slides.
The University of Texas – Pan American
CSCI 3327 Visual Basic Chapter 7: Arrays
The University of Texas – Pan American
Introduction to LINQ Chapter 11 10/28/2015 Lect 4 CT1411.
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look – Exercises UTPA – Fall 2012 This set of slides is revised from.
The University of Texas – Pan American
Introduction to LINQ Chapter 11.
CSCI 3327 Visual Basic Review: Final Exam
The University of Texas – Pan American
Introduction To Programming Information Technology , 1’st Semester
CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections UTPA – Fall 2012 This set of slides is revised from lecture slides.
The University of Texas Rio Grande Valley
Object Oriented Programming in java
CSCI 3328 Object Oriented Programming in C# Review: Exam II
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises UTPA – Fall 2012 This set of slides is revised from.
Access: SQL Participation Project
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
The University of Texas – Pan American
CSCI 3328 Object Oriented Programming in C# Chapter 11: Files and Streams -- Exercises UTPA – Fall 2012 This set of slides is revised from lecture slides.
CSCI 3328 Object Oriented Programming in C# Chapter 3: Introduction to Classes and Objects – Exercises UTPA – Fall 2012 This set of slides is revised.
The University of Texas – Pan American
CSCI 3327 Visual Basic Review: Exam I
CSCI 3328 Object Oriented Programming in C# Review: Exam II
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
The University of Texas – Pan American
MSIS 655 Advanced Business Applications Programming
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
Compiler Design Second Lecture.
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look UTPA – Fall 2012 This set of slides is revised from lecture.
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
Java: Variables, Input and Arrays
CSCI 3328 Object Oriented Programming in C# Review: Exam II
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays – Exercises UTPA – Fall 2012 This set of slides is revised from lecture slides of Prof.
CSCI 3328 Object Oriented Programming in C# Review: Exam I
Presentation transcript:

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 slides of Prof. John Abraham. -- Xiang Lian

Objectives In this chapter, you will do some exercises related to: LINQ Collections

Multiple Choices An array’s length is ______. Use the _______ property of the List class to find the number of elements in the List. A. GetLength B. GetLength() C. Length D. Length() An array’s length is ______. A. one more than the array’s last index B. one less than the array’s last index C. the same as the array’s last index D. returned by size() – 1 The process of ordering the elements of an array is called ____ the array. A. allocating B. sorting C. declaring D. initializing The LINQ ________clause is used for filtering. A. orderby B. from … in C. where D. select _______are classes specifically designed to store groups of objects and provide methods that organize, store and retrieve those objects. A. Int B. Classes C. Collections D. Objects

Multiple Choices (cont'd) To add an element to the end of a List, use the _____ method. A. insert B. Items C. add D. Item To get only unique results from a LINQ query, use the ______ method. A. Unique B. Only C. Distinct D. Solely To sort the elements of an LINQ query, use ___ clause. A. orderby B. ascending C. where D. select Which extension method can determine the number of elements in the result of an LINQ query? A. Sum B. Distinct C. Length D. Count

True/False Statements The where clause in an LINQ query is optional The orderby clause of an LINQ query by default sorts the array in descending order LINQ can query arrays of only primitive types LINQ queries can be used on both arrays and collections The Remove method of the List class removes an element at a specific index

True/False Statements (cont'd) To declare an integer array of two rows and five columns, the expression should be: int[] a = new int [3, 6]; To sort an integer array, myArray, in decreasing order, we can use the following LINQ query: var sorted = from e in myArray order by e descending select e To add an integer to a List variable, listScores, we can use: listScores.Items.Add();

Write a Program Assume a class Invoice includes 4 properties: PartNumber (int) PartDescription (string) Quantity of the item being purchased (int) Price (decimal) Write a program that performs queries over the array of Invoices objects: 1. Use LINQ to sort the Invoice objects by PartDescription; 2. Use LINQ to sort the Invoice objects by Price; 3. Use LINQ to select the PartDescription and Quantity, and sort the results by Quantity; 4. Use LINQ to select from each Invoice the PartDescription and the value of Invoice (i.e., Quantity*Price); 5. Use the results of the LINQ query in Part 4, select the InvoiceTotal in the range $200 to $500. new {e. PartDescription, InvoiceTotal = e.Quantity*e.Price} – anonymous type

Write a Program (cont'd) Write a console application program that inserts 30 random letters into a List <char>. Perform the following queries on the List and display your results: 1. Use LINQ to sort the List in ascending order 2. Use LINQ to sort the List in descending order 3. Display the List in ascending order with duplicates removed

Write a Program (cont'd) Declare an array, numArray, to hold 100 integer numbers Assign random numbers within [1, 100] into this array Use the LINQ query to sort this array Use the LINQ query to check whether a number 50 exists in this array