CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,

Slides:



Advertisements
Similar presentations
LINQ and Collections An introduction to LINQ and Collections.
Advertisements

Introduction to Arrays Chapter What is an array? An array is an ordered collection that stores many elements of the same type within one variable.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Arrays.
Extension Methods, Anonymous Types LINQ Query Keywords, Lambda Expressions Svetlin Nakov Telerik Corporation
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look 1 Xiang Lian The University of Texas – Pan American Edinburg,
For use of IST410 Students only Arrays-1 Arrays. For use of IST410 Students only Arrays-2 Objectives l Declaring arrays l Instantiating arrays l Using.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
©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 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
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.
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ 1 Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
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
1 Chapter 7 – Arrays 7.1 Creating and Accessing Arrays 7.2 Using LINQ with Arrays 7.3 Arrays of Structures 7.4 Two-Dimensional Arrays 7.5 A Case Study:
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
Neal Stublen How does XMLReader work?  XmlReader.Read() Advances to next node XmlReader properties access node name, value, attributes,
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
 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 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
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 4333 Database Design and Implementation – Exercise (5) Xiang Lian The University of Texas – Pan American Edinburg, TX
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections UTPA – Fall 2011.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
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.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg,
CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
1 CSC103: Introduction to Computer and Programming Lecture No 17.
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.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 7: Introduction to Object- Oriented Programming in Python – Exercises Xiang Lian The University of.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 5: Functions – Exercises Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
CSCI 4333 Database Design and Implementation – Exercise (5)
Introduction to LINQ and Generic Collections
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 3328 Object Oriented Programming in C# Chapter 7: Arrays
The University of Texas – Pan American
The University of Texas – Pan American
CSCI 3327 Visual Basic Chapter 8: Introduction to LINQ and Collections
CSCI 3328 Object Oriented Programming in C# Review: Exam I
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
CSCI 3327 Visual Basic Review: Final Exam
The University of Texas – Pan American
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
CSCI 3328 Object Oriented Programming in C# Review: Exam II
CSCI 4333 Database Design and Implementation – Exercise (5)
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
The University of Texas – Pan American
The University of Texas – Pan American
CSCI 6307 Foundation of Systems – Exercise (1)
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
CSCI 3328 Object Oriented Programming in C# Review: Final Exam
The University of Texas – Pan American
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.
CSCI 3328 Object Oriented Programming in C# Review: Exam II
CSCI 6307 Foundation of Systems – Exercise (5)
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.
Presentation transcript:

CSCI 3328 Object Oriented Programming in C# Chapter 8: LINQ and Generic Collections – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg, TX

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

Multiple Choices Use the _______ property of the Array 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 3

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 4

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 5

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(); 6

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, Invoices, of Invoice 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. 7

Write a Program (cont'd) Write a console application program that inserts 30 random letters into a List. 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 8

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 9

10