41
votes
Country code lookup for each line in a CSV file
Your loop is close to 200 lines, that's waaaay too long. That's long for a full class, let alone one method, let alone part of one method.
Why do you use ...
30
votes
Accepted
Find the odd occurrences in an array
There is a simple solution that does not require a dictionary:
...
27
votes
Accepted
PermMissingElem- find the missing element in a given permutation in C#
It is possible to solve the problem without sorting the array (which is expensive). The input array is actually a simple arithmetic sequence 1, 2, 3, 4 ... N+1, the ...
25
votes
Solving Fizz Buzz using LINQ in C#
Parallel computing and asynchonous computing are two separate things. While they might be similar in some cases, the two terms have two very distinct meanings in C#-land:
Asynchronous computing is ...
21
votes
Accepted
SudokuSharp Solver with advanced features
This is amazing. Especially for person who is not using C# every day for years.
My main concerns are
too many thing that are public that should be ...
17
votes
Country code lookup for each line in a CSV file
Instead of using linq lookups for the lists you should map your data into dictionaries, which are MUCH faster to access specific instance of your data, memorywise you might take a hit but the mapping ...
15
votes
Accepted
ExactlyOne extension method
Q&A
Is the code readable?
ExactlyOne states very clearly what the method is supposed to do.
source is null seems odd to ...
15
votes
Solving Fizz Buzz using LINQ in C#
Understanding your code was a bit of a challenge (albeit an interesting one).
Overall, I see a lot of function definitions that don't seem to accomplish anything. Why did you write
...
13
votes
Accepted
Filter data with optional parameters
IEnumerable<Registration> all = All(); // <-- this gets all registrations from
// the database.
This looks ...
12
votes
Accepted
12
votes
ExactlyOne extension method
mhmmm... I'm not so sure about this implementation. @dfhwze's points are valid but still, I find it's overengineered.
I prefer chaining these two alraedy available extensions that can do all ...
12
votes
Accepted
Given an array A[] and a number x, check for pair in A[] with sum as x
Your algorithm isn't the most efficient out there.
As you process the input, you can keep track of the numbers you have already seen and which numbers would complement those to sum to ...
11
votes
Accepted
Convert Foreach Loop into Linq in C#
I think you can extract small methods to simplify this code. Also you can try XPath to get specified sub-nodes and attributes.
And, yes, you can simplify this code ...
11
votes
Accepted
Sorting a list based on date and time
You should first do OrderBy and then you should do ThenBy instead of doing another OrderBy. ...
11
votes
Accepted
Enumerate list with filter criteria
I will assume that the CreditCard class is set in stone, otherwise I probably would store a DateTime in it and calculate ...
11
votes
PermMissingElem- find the missing element in a given permutation in C#
You could also solve it without sorting by xor all expected number and afterwards xor all elements from the array - that should be a little bit faster:
...
11
votes
Accepted
Take a desired string, iterate through objects to see if it exists in a given field and append a number until a unique string is found
There's certainly room for improvement.
Move that that Select(stringFieldFunction).ToList() out of the while loop. Iterating an ...
11
votes
11
votes
Checking a value in a string array in C#
Some of the naming seems off - it is a password checker but you are passing in and comparing a userName - but if you want a linq-ish solution you might try
...
10
votes
FizzBuzz in accordance with standards
This is how you end up with projects with forms with 25,000 lines of code. It's also how you end up with duplicated code.
Your (poorly named) Form1 class should ...
10
votes
Accepted
LINQ queries improvement - repetition of query
The first thing (and this is very minor) is that the expression a == true and simply a are identical. Thus you don't need all ...
10
votes
10
votes
Accepted
Building XML elements from a list using LINQ and foreach
The best way to discuss performance is by measuring it. I suggest you use BenchmarkDotNet and never roll your own solution.
Onto your question: it is safe to assume that LINQ will in most cases be ...
10
votes
Country code lookup for each line in a CSV file
if (values.Length < 3)
{
return;
}
if (values.Length >= 2)
{
How should in the second if the ...
10
votes
Accepted
Joining to in memory List
The dilemmas here:
query is an IQueryable. If you join it with offices, i.e. without ...
10
votes
Custom implementation of the linq Zip operator for different length lists
public static class Impl
{
public static IEnumerable<TResult> ZipNew<TFirst, TSecond, TResult>(
Names? The class would be more ...
10
votes
Custom implementation of the linq Zip operator for different length lists
I noticed a few things that can be improved:
Not all enumerators support Reset. Generator methods don't, for example, so calling ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
linq × 604c# × 588
performance × 80
entity-framework × 72
.net × 58
xml × 22
extension-methods × 20
algorithm × 18
sql × 17
beginner × 16
datetime × 15
comparative-review × 15
linq-to-sql × 15
strings × 14
hash-map × 14
asp.net × 14
iterator × 12
asp.net-mvc × 12
lambda × 12
generics × 11
.net-datatable × 11
functional-programming × 10
vb.net × 9
reflection × 9
expression-trees × 9