IAP C# 2011 Lecture 2: LINQ and Concurrency
IAP C# 2011 Lecture 2: Delegates, Lambdas, LINQ
Geza Kovacs
Two ways of thinking about operations on collections
? Task: I have an array of integers. I want a new array containing just the positive integers
? Imperative style: Use a loop
? With a Language Integrated Query (LINQ): Define a query (a request for information) that'll request the positive integers, and execute it
using System; using System.Collections.Generic;
static class MyMainClass {
static void Main(string[] args) { int[] arr = new int[] { 1, -1, 0, 4, -3, 2 }; var positiveList = new LinkedList(); foreach (int x in arr) { if (x > 0) positiveList.AddLast(x); } int[] positiveArr = positiveList.ToArray(); // contains { 1, 4, 2 }
} }
using System; using System.Collections.Generic;
static class MyMainClass
{ static void Main(string[] args) {
Entry point for application
int[] arr = new int[] { 1, -1, 0, 4, -3, 2 };
var positiveList = new LinkedList();
foreach (int x in arr)
{
if (x > 0)
positiveList.AddLast(x);
}
int[] positiveArr = positiveList.ToArray();
// contains { 1, 4, 2 }
}
}
using System; using System.Collections.Generic;
static class MyMainClass {
Array initialization
static void Main(string[] args) {
int[] arr = new int[] { 1, -1, 0, 4, -3, 2 };
var positiveList = new LinkedList();
foreach (int x in arr)
{
if (x > 0)
positiveList.AddLast(x);
}
int[] positiveArr = positiveList.ToArray();
// contains { 1, 4, 2 }
}
}
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- c 3 linq cornell university
- iap c 2011 lecture 2 linq and concurrency
- query expression lambda expressions
- calling functions in linq queries
- about the tutorial
- introduction to linq language integrated query
- type inference 3 0 features components in linq
- linq language features for concurrency among other
- example of a linq query tutorialspoint
Related searches
- c reactive protein 2.9
- algebra 2 worksheet and answers
- genesis 2 questions and answers
- difference between 2 1 and 3 1
- difference between 2 1 and 4 1
- form 2 questions and answers
- c reactive protein 2 6
- c reactive protein 2 4
- 192 168 0 2 username and password
- trid 2 0 and construction loans
- c reactive protein 2 9
- grade 2 stories and questions