# Tag Info

### 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. ...
• 14.6k

### 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: ...
• 8,498
Accepted

• 14.6k
Accepted

### Simple generic cache

You say cache I say memory leak. You haven't given much thought to your eviction policy yet and that's 95% of the work in writing a decent cache. Your expired entries are only removed when someone ...
• 16.6k
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 ...
• 43.8k
Accepted

### Reusability vs simplicity in a small game with a set of interfaces

The problem, however, is that this means when creating my classes, I need to ferry around this TPos generic construct to places where it doesn't make sense to define it. I'm left creating new ...
• 58.1k
Accepted

### Generic method to split provided collection into smaller collections

Your implementation is not bad for a no-LinQ solution. But there's always room for improvement. First I'll provide a LinQ solution that provides a clean way to return a chunked list: ...
• 5,553
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 ...
• 314
Accepted

### Generic, thread-safe MemoryCache manager for C#

Short version: it looks like you're just trying to get a per-type ObjectCache. That's a basic singleton pattern, so I'm unsure what you're trying to gain through all this extra cruft in the class. If ...
Accepted

### VHDL mux in need of generics

There are 4 ways to a solve this: Solution 1: You can define a fixed width STD_LOGIC_VECTOR (SLV), which can be used to construct other vectors (let's call them STD_LOGIC_VECTOR_VECTORs (SLVV). <...
• 587

### Simplifying a series of type checks and casts in a generic method

You should create a Dictionary<Type,Type> that would associate your object's type with their DTO equivalent, so you wouldn't need any ...
• 12.2k
Accepted

### Convert a boxed integer to an nullable integer with potentially different type

You should probably add IConvertible restriction on T, since it is used by Convert.ChangeType...
• 13k

### Empty Interface usage - Is this a code smell?

It may appear to some as code smell, but it's a practice in use in the .net framework defined as 'marker interfaces'. IReadOnlySessionState is one of these and as ...
• 251

### Convert a boxed integer to an nullable integer with potentially different type

I'm not sure if you understand what boxing means because you use an int in the example. Boxing is the process of converting a value type to the type ...
• 43.8k

### Reusability vs simplicity in a small game with a set of interfaces

Your interfaces are inconvenient, and you are falling in to a trap of convenience that actually leads to inconvenience..... let me explain... C# makes it easy to create the getter/setter methods for ...
• 96.7k
Accepted

### Instantiating a run-time implementation of an interface

Two parts to this review: the 1-liner for the newInstance() the general mechanism of the method newInstance() This code will work, but only for a subset of Collections. For example, there are many ...
• 96.7k
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 ...
• 6,418

### 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 ...
• 43.8k
Accepted

### Generic cached value class mimicking Lazy<T>

First off, never lock on this. You never know who else is locking on that instance. Conversely, clients don't know that the cache is locking on itself either. For ...
• 1,167
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 ...
• 5,714

### Simple generic double buffer pattern

Please correct me if I am wrong, but isn't such scenario possible with accepted answer? ...
Accepted

### Binary Heap where a comparison delegate is used

Performance bug private void BubbleUp(T element) { int elementIndex = _elements.IndexOf(element); ... This is $O(n)$, which completely oblitirates \\$O(\...
• 25.3k
Accepted

### Empty Interface usage - Is this a code smell?

An empty interface is a code smell. In C# you can use attributes to mark a class instead of making it implement an empty interface. As I suggested in my comment, you can use reflection to build your <...
• 6,557
Accepted

### Generic deque implementation

This class looks reasonably complete, and fully usable. There are some issues I see that may affect the experience though, and also some suggestions about a better way to do it... Issues: Why do you ...
• 96.7k
Accepted

### Cutting it to Pages

Compiler Warning This line gives you a compiler warning because it's not using generics: List activeList = listOfLists.get(pageNumber); it should be ...
• 58.1k
Accepted

### How can I make this StringToCollections method more generic?

Consistency: Don't mixup using var and declaring your variables explicitly. Choose one of the two, preferably var. Combining ...
• 5,553
Accepted

### Simple Generic output for Deserializer

Here are a few remarks. I'm not perfect or write perfect code but I hope these tips will help write better code: Naming consistency: It would be easier to understand if the names of your two methods ...
• 5,553
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 ...
• 8,169