Kittoes0124
  • Member for 9 years, 11 months
  • Last seen more than a week ago
Password maker in C#
9 votes

Fully Refactored Code: see this Gist Example Usage: static void Main(string[] args) { var generator = new PasswordGenerator(new PasswordGeneratorOptions { ...

View answer
Unmanaged byte array to managed structure
6 votes

Expanding on my comment; below you'll find a very simple program that compares the method I suggested with your original example. The results on my machine show that the MemoryMarshal class is about ...

View answer
LINQ-ifying Colour Generation from Strings
5 votes

There are an infinite number of ways to do this but one possible approach would be to use a dedicated hash function to compress your inputs; out of sheer laziness and convenience I chose to use the ...

View answer
A betting game using a dice class in C#
4 votes

First off, let's start by refactoring the Dice class: public sealed class Die { private readonly Func<int, int, int> randomNumberGenerator; public int MinimumValue { get; } public ...

View answer
Generate cryptographically secure random numbers in a specific range
4 votes

I believe one can avoid the bias problem by generating a random float between [0..1) and then normalizing the value between x and y instead of clamping: private static RandomNumberGenerator Rng = new ...

View answer
Asp.net networking/restclient layer
2 votes

I thought that what you have is actually quite solid; my only suggestion is that you should take advantage of C#'s features in order to slightly clean things up. First, let's create an options object ...

View answer
Database abstraction class in C#
2 votes

If you're going to spend the time abstracting things then you probably want to invest some effort in refactoring a lot of your common logic into helper functions. Starting with the very first issue, a ...

View answer
Determine objects to delete from a database
2 votes

No need to implement IEquatable on every DTO, nor is a common interface required. Use generics and a lambda to access a property of a given T: public static IEnumerable<T> GetItemsToDelete<T,...

View answer
LINQ Extension methods MinBy and MaxBy
1 votes

AggByA: baseline two-pass method presented by the OP. AggByB: one-pass method using Aggregate suggested by @PeterTaylor AggByC: one-pass method implemented by hand I left most error handling to the ...

View answer
Accessing Properties by Name
Accepted answer
1 votes

Updates: I have refactored class based on a combination of all of the feedback here, on the linked question, and a lot of benchmark results. The current implementation has been split into ...

View answer
Nth Index of Char in String
Accepted answer
1 votes

By taking advantage of the Math.Sign operation and avoiding the use of IndexOf and LastIndexOf (as suggested by the great answers provided so far) I have come up with a version that avoids having two ...

View answer