Questions tagged [linq]
Language INtegrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages.
33
questions
85
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
260
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
667
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
...
3
votes
2
answers
604
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 ...
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 ...
11
votes
1
answer
612
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 ...
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 ...
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 ...
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
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
1
answer
215
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:
...
9
votes
5
answers
964
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
15k
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
3
answers
266
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 ...
7
votes
1
answer
331
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:
...
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 ...
6
votes
2
answers
1k
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 ...
5
votes
1
answer
3k
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 ...
5
votes
3
answers
9k
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 ...
5
votes
1
answer
134
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 ...
5
votes
2
answers
385
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
1
answer
354
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
2
answers
184
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:
...
4
votes
1
answer
1k
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" ...
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 ...
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
3k
views
Is ToIEnumerable<T> good practice?
I have an extension method that does this:
...
3
votes
2
answers
4k
views
Group list into elements with same value
This is my Result class:
...
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
160
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 ...