Solved

# Enumerable Skip

Posted on 2010-09-20
281 Views
I have two codes as follow,

Code 1
``````           int[] grades = { 1, 2, 3, 4, 5 };

var q = from c in grades.Skip(1)
select c;

foreach (int number in q)
Console.WriteLine("{0}", number);
``````

Code 2
``````            int[] grades = { 1, 2, 3, 4, 5 };

var q = from c in grades
where c > 1
select c;

foreach (int number in q)
Console.WriteLine("{0}", number);
``````

They provide the same result.
If the list contains billion values and filter condition is different, base on the performance which one is better?
0
Question by:mawingpui
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 16

Assisted Solution

kris_per earned 166 total points
ID: 33717728

Code 1 which uses Skip would be faster as Code 2's 'where c > 1' is checked on every item.
0

LVL 8

Accepted Solution

Gururaj Badam earned 167 total points
ID: 33723781
I don't think there will be any performance difference between the two.

The third way would be - var q = grades.Where(x => x > 1);

a more simpler notation though.

I can only recommend you to test to see the execution time required in all 3 approaches and decide which one is better suitable for you.
0

LVL 3

Assisted Solution

CyberSoft earned 167 total points
ID: 33769044
There are actually two fundamental differences in the logic of the two code-snippets above.

Code 1: Ignores the first record in the result set (regardless of value)

Code 2:: Excludes values from the result set where the grade is less than or equal to 1

If there is ordering involved or other records with the same values as in the where clause you'll get two distinctly different result sets which means you may not necessarily get the same results from both queries.

HTH
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Progress
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
###### Suggested Courses
Course of the Month2 days, 20 hours left to enroll