Skip to main content
39 votes

Own implementation of Lazy<T> object

is the current implementation 'safe'? Absolutely not. The fact that you had to ask this question indicates that you do not understand enough about threading to build your own mechanisms like this. You ...
Eric Lippert's user avatar
19 votes
Accepted

Own implementation of Lazy<T> object

Having backported Lazy to .NET 2.0, I want to offer a variant... First of all, this looks a lot like LazyInitializer. If that works for you, then there is no need to go about creating a ...
Theraot's user avatar
  • 314
14 votes
Accepted

Heap implementation for numeric types

Memory management You never delete[] arr;, which leaks memory. Not a good thing! There are multiple ways to fix this: Adding correct calls to ...
hoffmale's user avatar
  • 6,528
14 votes

Own implementation of Lazy<T> object

is there anything else I'm missing that I should be concerned about in a high traffic application? Yes, your Lazy<T>.Value isn't generic anymore but an ...
t3chb0t's user avatar
  • 44.7k
13 votes
Accepted

Copy a similar list to another

Small things Your code styling is generally good, but a few possible improvements: You can add a second generic type parameter to your method to avoid the need to cast to ...
Ben Aaronson's user avatar
  • 5,774
12 votes

Generic C++ Class to Associate enum Values with Strings for Translation

Consider using magic enum instead. It basically automates this. Alternatively, for example if you want other spellings for the string representations, I found X-macros very useful: ...
chrysante's user avatar
  • 278
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
Accepted

Method for create a copy of List<T>

Given that arrayCopy has exactly one line, it's not clear that there's much value in having it extracted as a method. toArray() ...
Eric Stein's user avatar
  • 6,726
10 votes

Copy a similar list to another

for (int i = 0; i < propInfos.Length; i++) Any particular reason why you're not using foreach (var prop in PropInfos) here? <...
Snowbody's user avatar
  • 8,682
10 votes

Turning a byte array into a C# object whose type is unknown at compile time

...
t3chb0t's user avatar
  • 44.7k
10 votes

Own implementation of Lazy<T> object

Meaning that I have to put half of my logic concerning the lazy property in the constructor, and having more boilerplate code. This is a little speculative, but I think you have an XY problem. You're ...
jpmc26's user avatar
  • 1,243
10 votes
Accepted

Generic C++ Class to Associate enum Values with Strings for Translation

It's not going to be perfect Unfortunately, until we get true enum reflection in C++ (supposedly in C++26), any solution to map enum values to strings is going to have some issues. Your solution ...
G. Sliepen's user avatar
  • 69.3k
9 votes

Declarative type comparer

Very nice implementation; I always like seeing your code here. I really only have five very minor opinions on this implementation: I'm not sold on expr as an ...
Jesse C. Slicer's user avatar
9 votes

Generic data structures in C

- float float constants need the suffix f: ...
alx - recommends codidact's user avatar
9 votes
Accepted

Classes representing 2D points and pixels

A fine example how modern C# can make your life so much easier! But first things first: Errors and maybe errors Your GetHashCode() is realy weak! Just take two example points (1|1) and (0|32) and ...
Matthias's user avatar
  • 106
8 votes
Accepted

Generic Dictionary Equality Comparer

You said you built this specifically so you can use dictionaries as keys in other dictionaries? In that case, you've got a problem. Consider the following demonstration: ...
Pieter Witvoet's user avatar
8 votes

Generic linked list implemented in pure C

GenericList.h and GenericList.c Generally this is excellent code as long as it is a stack you want. It seems that what is created is really a generic stack implemented on a linked list rather than a ...
pacmaninbw's user avatar
  • 26.1k
8 votes
Accepted

Generic matrix library in Java

Dense matrix multiplication in 15572 ms. Going by the demo code I assume this was the product between two 1000x1000 matrices. By my estimate based on old code the raw operations by themselves could ...
user555045's user avatar
  • 12.4k
7 votes

Heap implementation for numeric types

An addendum to hoffmale's excellent answer (read and upvote that one first!): Prefer to initialize members, rather than assign them during construction: ...
Toby Speight's user avatar
  • 88.4k
7 votes
Accepted

Immutable builder and updater

You use IList<> where you should use ICollection<>. I've rarely encountered a scenario where ...
IEatBagels's user avatar
  • 12.7k
7 votes

Generic Heap Implementation in C#

The code in question is easy to read and understand. You have named your variables and methods well, using the recommended naming and casing styles. The code in question is well documented as well. ...
Heslacher's user avatar
  • 51k
7 votes

Generic Heap Implementation in C#

Nice Code! One simple suggestion. Add a constructor with capacity and initialize the List with that capacity. If you don't have the capacity preinitialize everytime you Add a new element to the list ...
Pablo Rausch's user avatar
7 votes
Accepted

generic implementation of median

It modifies the input I think it is surprising that an operation that is intended to just give you some statistics back is going to modify the input. In the test code you also test it on ...
G. Sliepen's user avatar
  • 69.3k
7 votes

An Attempt at Creating Generic Min()/Max() for Fundamental Types

The compound expression statement would restrict the scope of x and y, but there may still be conflicts with variable names that ...
Madagascar's user avatar
  • 10.1k
6 votes
Accepted

Collection with Generic Index

The problem There is a massive hole in your logic here. You are relying on the fact that there exists a property whose type is equal to the name of the property. ...
Flater's user avatar
  • 5,720

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