Skip to main content
32 votes

Extension method replacing elements from an IEnumerable<T> collection

Why didn't Microsoft include this in the .NET framework? Probably because it can be realized in one line with Select: ...
JanDotNet's user avatar
  • 8,538
25 votes
Accepted

Extension method replacing elements from an IEnumerable<T> collection

I cannot comment about the speed because I didn't benchmark it but there are two obvious improvements. add an IEqualityComparer<T> as a third parameter so ...
t3chb0t's user avatar
  • 44.3k
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,919
20 votes
Accepted

Extension method splitting string on each capital letter

With regex it's virtually a one-liner: ...
t3chb0t's user avatar
  • 44.3k
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
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
11 votes

ExactlyOne extension method

This is for dfhwze as per comment: ...
Jesse C. Slicer's user avatar
10 votes
Accepted

Selective updates to immutable types

You should be able to cut the code length and improve performance, by simplifying the algorithm. Here are some of the problems I've noticed in your implementation: You're currently processing all of ...
Denis's user avatar
  • 8,508
10 votes
Accepted

Split string with adding separator to substring

Review You use very clean and strong names for all your variables so it's very easy to understand your code. You too often go without {}. Especially the double <...
t3chb0t's user avatar
  • 44.3k
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

Build WHERE clause for search conditions

Sanitizer is a dangerous misnommer IMO. A better name could be NameQuoter, since that's what it does: it uses the RDBMS-specific ...
Mathieu Guindon's user avatar
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
9 votes

Solving Fizz Buzz using LINQ in C#

Now, I fully congratulate you on the exercise - it's an interesting problem and I think a great learning opportunity. However, to learn from this we must acknowledge it's shortcomings. I think the ...
NPSF3000's user avatar
  • 715
8 votes
Accepted

Removing exact instances of elements in one list from another

Additional to the valid point from Rick Davin: 1) You can drop the Contains because IndexOf returns -1 if the item is not ...
JanDotNet's user avatar
  • 8,538
8 votes
Accepted

Extension method to retrieve list of days in the current week

Let's talk about two major things in this: building a modular API, and Unit Testing. This can be easily unit tested, you should have 7 tests, one for a date in each day of the week. Let's pick a Week ...
Der Kommissar's user avatar
8 votes
Accepted

Checking if string contains other strings

I like the ternary operator but in this case I wouldn't use it because a single expression that makes sure both variables are valid and then searching for the strings is easier to understand I think. ...
t3chb0t's user avatar
  • 44.3k
8 votes

LINQ for generating all possible permutations

Using line breaks and {} in code is not a crime :-P Only because we have the nice => doesn't mean we have to use it ...
t3chb0t's user avatar
  • 44.3k
7 votes
Accepted

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

This is not realy shorter then your example but it will work with any enumerable and does not require a count/length to be known: ...
t3chb0t's user avatar
  • 44.3k
7 votes
Accepted

Custom struct design: Range

Only targeting public struct Range If possible a struct should be immutable so you shouldn't let a user of this struct set the ...
Heslacher's user avatar
  • 50.4k
7 votes

Extension method to retrieve list of days in the current week

You already know that you cannot test this extension because Now is hardcoded so tests will yield different results each time. To overcome this problem you can make ...
t3chb0t's user avatar
  • 44.3k
7 votes
Accepted

Adding extension methods to IServiceCollection in ASP.NET Core

Instead of doing services.AddThemes(options => { options = Configuration.GetSection("Themes").Get<ThemesOptions>(); }); you could use ...
saluce's user avatar
  • 186
7 votes
Accepted

Finding MinMax values and returning a tuple as a result

What bothers me with the tuple is that fields are not readonly and we cannot prevent users of the method to mess up and break flow. We cannot prevent everything and sometimes it's just easier and ...
t3chb0t's user avatar
  • 44.3k
7 votes
Accepted

Writing a generic casting extension-method

This design looks to me like a massive violation of KISS. For a start, I don't see the benefit of CastTo and CastTo<T>. It ...
Peter Taylor's user avatar
  • 24.1k

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