Hot answers tagged

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.1k
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,528
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.1k
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.1k
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
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 ...
Mark Shevchenko's user avatar
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. ...
Pankaj Gupta's user avatar
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 ...
AndreySarafanov's user avatar
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,528
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

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 ...
nhgrif's user avatar
  • 25.2k
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 ...
Groostav's user avatar
  • 279
10 votes

LINQ queries improvement - repetition of query

Extension methods to the rescue! ...
RobH's user avatar
  • 16.9k
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.3k
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,010
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

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