Hot answers tagged

41 votes

Converting DataTable to List of class

I created an extension method for DataTable to convert them into a List<T> ...
user avatar
  • 621
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 ...
user avatar
  • 10.6k
30 votes
Accepted

Find the odd occurrences in an array

There is a simple solution that does not require a dictionary: ...
user avatar
  • 8,498
26 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 ...
user avatar
  • 686
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 ...
user avatar
  • 2,889
24 votes
Accepted

Single line FizzBuzz solution in LINQ

Overall, I like this. It is concise, and neat, and all. My only beef is the nested ternaries. In general, ternary operator precedence is complicated by the lack of blocks.... The need for the ...
user avatar
  • 96.7k
20 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 ...
user avatar
19 votes

Imposing a sort order on a query

I'm not a member of the “goto is evil and must not be used under any circumstances” camp. Especially in performance-critical low-level routines, it can be useful ...
user avatar
  • 4,220
18 votes

Linq me a FizzBuzz

I'd prefer to use the String.Join method instead of the Aggregate: ...
user avatar
  • 4,591
18 votes
Accepted

Imposing a sort order on a query

You could use goto, but you can also just define a function, as the label returns a value anyways. For example, your label ...
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 ...
user avatar
16 votes
Accepted

Increment up the build number in AssemblyInfo.cs on every build

Why not use Regex.Match instead of using those confusing joins/splits? Unless you are purposely trying to code golf this, doing it using regular expression is much ...
user avatar
  • 318
16 votes
Accepted

I had one job to do

I would say yes, there is value in removing the foreach loop, because your code will more appropriately mirror what you're expecting to happen versus what can happen. It's unclear to someone looking ...
user avatar
15 votes

Single line FizzBuzz solution in LINQ

Your code is nice, relatively simple and a good attemp at LINQ - I've written very similar code before. However I have the following critiques: A list is created unnecessarily, eagerly loading the ...
user avatar
  • 715
15 votes

Using C# properties for simple operations, where should I draw the line?

Methods Set and Get Properties through their Get and Set ...
user avatar
  • 28.5k
15 votes
Accepted

Using C# properties for simple operations, where should I draw the line?

I think that most things are said, I recapitulate and add some of my own stuff: As Jesse said, I'd use Any instead of Where + <...
user avatar
  • 301
15 votes
Accepted

Wait, is this... LINQ?

Decomposition There are redundancies in translating from Array and Collection. Consider these three snippits ...
user avatar
  • 2,381
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 ...
user avatar
  • 13.8k
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 ...
user avatar
14 votes
Accepted

Fetching data from a database

You can try the .Any function on IQueryable. It is made for checking if there are any records. Remember that .Any() has an ...
user avatar
  • 199
14 votes
Accepted

LINQ query that filters elements from a list of object

You can simply combine the conditions inside the FirstOrDefault() like ...
user avatar
  • 49.9k
13 votes

Increment up the build number in AssemblyInfo.cs on every build

Don't try to be a badass cowboy. ☺ Stuffing everything onto one line of code is trying to be badass. You could improve clarity simply by adding whitespace. Producing an incremented version number ...
user avatar
13 votes
Accepted

Update first and last item in List<T>

The performance of your current code depends a little about the implementation of the list, but what I primarily would have done is to extract first and ...
user avatar
13 votes

Sudoku Solver - Recursive Solve

At a really quick glance at the Section.RefactorPossibilities() method I can give you some general suggestions be consitent with the style you use. Here the ...
user avatar
  • 49.9k
13 votes

LINQ query that filters elements from a list of object

What you are doing is filtering PersonResultList to only include female genders. Joining to add information from PersonList ...
user avatar
  • 403
13 votes
Accepted

Filter data with optional parameters

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

Get distinct combinations of numbers

Let's talk algorithms, and complexity..... and what the actual problem is that you are trying to solve. Background Three concepts: distinct, permutation, and combination Distinct Distinct values ...
user avatar
  • 96.7k
12 votes

Imposing a sort order on a query

Goto's are a poor-man's function without the return semantics. Take your code, add a function, and bingo! ...
user avatar
  • 96.7k
12 votes
Accepted

Using Linq instead of multiple foreach loops

The LINQ would be: ...
user avatar

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