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 ...
BCdotWEB's user avatar
  • 11.2k
30 votes
Accepted

Find the odd occurrences in an array

There is a simple solution that does not require a dictionary: ...
JanDotNet's user avatar
  • 8,538
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 ...
gfv's user avatar
  • 696
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 ...
JAD's user avatar
  • 2,909
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 ...
Vadim Ovchinnikov's user avatar
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 ...
Janne Matikainen's user avatar
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 ...
dfhwze's user avatar
  • 13.9k
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 ...
Tanner Swett's user avatar
13 votes
Accepted

Filter data with optional parameters

IEnumerable<Registration> all = All(); // <-- this gets all registrations from // the database. This looks ...
t3chb0t's user avatar
  • 44.3k
12 votes
Accepted

Using Linq instead of multiple foreach loops

The LINQ would be: ...
Johan Larsson's user avatar
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 ...
t3chb0t's user avatar
  • 44.3k
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 ...
JAD's user avatar
  • 2,909
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: ...
JanDotNet's user avatar
  • 8,538
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 ...
Pieter Witvoet's user avatar
11 votes

ExactlyOne extension method

This is for dfhwze as per comment: ...
Jesse C. Slicer's user avatar
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 ...
AlanT's user avatar
  • 3,599
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 ...
Jeroen Vannevel's user avatar
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 ...
Heslacher's user avatar
  • 50.4k
10 votes
Accepted

Joining to in memory List

The dilemmas here: query is an IQueryable. If you join it with offices, i.e. without ...
Gert Arnold's user avatar
  • 2,020
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 ...
Peter Taylor's user avatar
  • 24.1k
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 ...
Pieter Witvoet's user avatar
10 votes
Accepted

LINQ for generating all possible permutations

English language These are relatively minor issues, but fixing them might help other people to use / maintain your code. The verb corresponding to permutation is permute. I'm pretty sure that ...
Peter Taylor's user avatar
  • 24.1k
9 votes

Checking whether relations are equal to foreign fields using LINQ Any()

Can you not simply do SequenceEqual? ...
Nick Spicer's user avatar
9 votes
Accepted

Climbing the stairs

The code below is my C# Method and I only want to refactor the for-loop on line 13 I think. Sorry but you won't only get this, because your code has a large number of problems. Let us begin at ...
Heslacher's user avatar
  • 50.4k
9 votes
Accepted

Convert XML to CSV

First of all, I'd split the convert method out into it's own thing - separate from the loading and saving: ...
Pj-'s user avatar
  • 106
9 votes

Filter data with optional parameters

I would do it differently. U have too many parameter, use some model for this: ...
DawidP's user avatar
  • 131
9 votes

Solving Fizz Buzz using LINQ in C#

The comments mention being reusable as the main goal of the code. It is however far from it. The main issues I see with most of the extension methods above: Looking at the name of the methods (and ...
D. Jurcau's user avatar
  • 3,010

Only top scored, non community-wiki answers of a minimum length are eligible