Questions tagged [linq]

Language INtegrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages.

Filter by
Sorted by
Tagged with
84 votes
5 answers
25k views

SudokuSharp Solver with advanced features

Even though it's the first time I'm writing something this "big", it feels like I know C# quite well (it is very similar to Java after all). It's been nice to learn LINQ also and I am very impressed ...
10 votes
1 answer
250 views

Linq-to-Sage Implementation

Following-up on my last question where I wrapped the Sage API with a familiar IRepository interface, I decided to push the abstraction a step further, and... ...
40 votes
2 answers
5k views

Wait, is this... LINQ?

Context I'm working on a little project that consists in a series of Microsoft Excel add-ins (.xlam). The code being submitted for review here, is located in the ...
17 votes
3 answers
2k views

ExactlyOne extension method

I often find in codebases something on the order of if (sprockets.Count() > 0) which is easily replaced with LINQ's ...
6 votes
1 answer
645 views

Shuffling an arbitrary list or sequence

After reading this question I wanted to write a short example of how a list or sequence could be shuffled in .net. The result turned out to not be very short: Program.cs ...
  • 2,919
3 votes
2 answers
568 views

Countable and uncountable sets in .NET (IEnumerable and Predicate)

There is a full featured support of countable sets in .NET: IEnumerable<T>. What about uncountable sets; sets defined by predicate? How can they be ...
  • 6,123
24 votes
5 answers
17k views

Single line FizzBuzz solution in LINQ

Now FizzBuzz itself isn't a big challenge but I agree that it can be a good tool to see if someone can code or not. I wanted to practice my LINQ a little bit so here's my single line FizzBuzz ...
14 votes
7 answers
4k views

Imposing a sort order on a query

I've always been told "never use goto, there's always a better way" and for the longest time I just accepted it. Lately though, I've been running into such scenarios in which I have to repeat this bit ...
  • 1,961
11 votes
2 answers
3k views

Poker Hand Evaluator, take 2

This is following up on my previous attempt, which was admittedly done fast and not-so-well. This code attempts to allow comparing two poker hands to determine a winner, not only evaluating a given ...
11 votes
1 answer
584 views

C++ linq-like library

I want to implement something like C# Linq in C++ Currently only select and where is implemented, but others should be fairly ...
10 votes
1 answer
211 views

Refactor VB.NET to C#.Net using Linq

I am rewriting a VB.NET application in C#. I will not subject you to the original code because it's pretty messy. Below is the converted C# code: ...
  • 583
10 votes
3 answers
2k views

Tracking Entity Changes (not EF)

So, I kept refactoring my Sage300 API wrapper - I wanted the client code to feel just like using Entity Framework - this is the closest I got to it: ...
10 votes
4 answers
7k views

Split IEnumerable by predicate

In order to divide an IEnumerable in C# by a predicate, I implemented the following (in a static class): ...
10 votes
6 answers
3k views

Too Many Staff Meetings

I recently got in really deep on a question to find the overlapping meetings and I rewrote a bit of the code and added some things to the code, and I would just like a general review of my code and ...
  • 28.6k
9 votes
5 answers
962 views

Update grid from source hierarchy

In this question I answered with this Linq. While it does what I was looking for, I am not sure how easy the linq queries are for others to follow. So I am looking for feedback on formating, what ...
8 votes
4 answers
14k views

Filter data with optional parameters

I would make a filter to filter my data using next parameters: First name Last name Language Profile A minimum date of registration A maximum date of registration Success All filter options are not ...
7 votes
1 answer
325 views

LINQ Provider: Supporting Projections

Up until recently, my LINQ-to-Sage provider didn't support projections, so the client code had to explicitly "transfer" to LINQ-to-Objects, like this: ...
7 votes
3 answers
263 views

Enumerating new articles whose publication start date has passed

(cn.PublishEnd == null || cn.PublishEnd < DateTime.Now) vs (cn.PublishEnd ?? DateTime.MinValue < DateTime.Now) Which ...
  • 357
6 votes
2 answers
978 views

C# - Linq - Techniques for avoiding repeating same pieces of code

I am writing a piece of code for C# Web Api, letting the clients to pass a column name and sort direction as parameter. Although there are, like, 30-ish properties, so the following code (despite it ...
user avatar
6 votes
1 answer
1k views

IQueryable Extensions working on expression for collection property

Followup to Repository searching code duplication My goal currently is to make the current implementation of my repository's IQueryable filtering less duplicative. First, I looked into passing ...
5 votes
1 answer
351 views

Displaying information about an order when selection changes

I feel like just because the below works doesn't mean it is correct, I want to improve it but I can't really figure out how. Besides the fact it is down right ugly I feel the performance could be ...
5 votes
3 answers
4k views

Creating a CSV stream from an object

I have this code that gets a CSV string from a list of objects where the first row in the string is the object's properties and the rows underneath are the properties values. I then create a ...
  • 185
5 votes
1 answer
130 views

Categorize episode-file names - Follow up

This is a follow up to this question. I have implemented changes to the code as they were suggested in the previous question and have made a few changes of my own. But it has been mentioned that the ...
  • 585
5 votes
1 answer
2k views

IndexOrDefault that functions like FirstOrDefault

I don't know why this is not in the .NET Library, but I need to be able to use an index against a list and not have it throw an exception if it is outside the bounds of the list. This is what I came ...
  • 305
5 votes
2 answers
384 views

Getting list of daily team goals

The old code I had before was atrociously slow but after some advice and research I was able to take a 2-5 minutes run time down to about 5-30 seconds. That is acceptable, but still looking to have ...
5 votes
2 answers
173 views

LINQish command line parser

I needed to parse some command line switches from a string and I tried to do it the easy way so I just wrote this: ...
  • 44.1k
5 votes
1 answer
423 views

Transliterate between Cyrillic and Latin scripts

I want to get a code review on the following transliteration code. I wrote it because there were some libraries that I have tried and they were specifically failing with the name "Yuliya" ...
  • 665
4 votes
3 answers
3k views

Is ToIEnumerable<T> good practice?

I have an extension method that does this: ...
4 votes
2 answers
12k views

Poker Hand Evaluator Challenge

This week's review challenge is a poker hand evaluator. I started by enumerating the possible hands: ...
4 votes
3 answers
7k views

Factoring WHERE clauses in IQueryable

I recovered some spaghetti code and I have to refactor it. I do not want a method with over 200 lines, for me it is not object oriented programming. I am trying to ponder on the question and would ...
3 votes
2 answers
3k views

Group list into elements with same value

This is my Result class: ...
  • 309
3 votes
4 answers
4k views

Alternative way to extract the most recent file using LINQ

All, I have written some code to get the latest files from a directory, the files I am looking for contain the string sProcScript = "sProcScript" and in the ...
2 votes
1 answer
145 views

Performance issue with empty lists

Here's my updated version of the problem I posted at Calculating time windows for entities, adding in suggested changes as well as a change I did so that the Reflection is 'cached' in a ...