Jeroen Vannevel
  • Member for 9 years
  • Last seen more than a week ago
Custom Exception.ToString() formatter
Accepted answer
8 votes

private const string Space = " "; There's little point in storing this in a variable: it's never going to change anyway and you're not clarifying any of the intent. I'm fully aware that is a space ...

View answer
Building XML elements from a list using LINQ and foreach
Accepted answer
10 votes

The best way to discuss performance is by measuring it. I suggest you use BenchmarkDotNet and never roll your own solution. Onto your question: it is safe to assume that LINQ will in most cases be ...

View answer
Calculating the max difference between any 2 numbers from an array
3 votes

Right now you're doing this: For each value Read value Store value in array Sort array Subtract highest from lowest That's a lot of work and inefficient in multiple ways: You're keeping track of ...

View answer
A reference source for primes up to 64K (for unit tests)
2 votes

To get most of the stylistic issues out of the way, I ran your code through my project VSDiagnostics and it added braces, corrected identifiers according to naming conventions and changed a few things ...

View answer
Comparing Equals() method from MSDN
Accepted answer
13 votes

I like my implementation as it's much more succinct Which isn't necessarily a good thing: we care about readable code, not about oneliners. It means we don't use 5 lines to write what can be written ...

View answer
Unit Testing the Duck
Accepted answer
6 votes

I don't believe a Semaphore is needed in the first place. Remove it, register an event handler and continue your "act" and "assert" phase inside it. Something like this: parser.State.StateChanged += ...

View answer
Java spaghetti code
2 votes

catch (OutOfMemoryError error) { } catch (Error e) { } Errors should never be caught in Java, only exceptions. An error differs from an exception in the sense that an error is the kind of problem ...

View answer
An AES Cryptography Wrapper
3 votes

This feels a little clumsy: public string AesDecrypt(string cipherText, bool throwExceptions) { if (throwExceptions) { cipherText = AesDecryptInternal(cipherText); } else {...

View answer
Comparing two lists
Accepted answer
11 votes

You can shorten the following snippet by using LINQ and a projection: List<Member> Members = new List<Member>(); foreach (SPListItem mItem in GetList(Url).Items) { Member m = new ...

View answer
Generate all available numbers for pattern, shuffle and save to multiple files
2 votes

//here I'm determining how many numbers i must generate? //can't his be done simpler? var count = Convert.ToInt32("1".PadRight(9 - prefix.Count() + 1, '0')); Yes, I think it can be simpler. You ...

View answer
Code Fix - changing accessibility
Accepted answer
2 votes

Addressing your comments first: Should I even be implementing multiple code fixes in a single CodeFixProvider? - the API definitely supports it but it feels it could easily get out of hand It's ...

View answer
A completely repetitive console prompt, a completely repetitive console prompt
12 votes

You can remove all your if-statements and use Convert.ChangeType() instead. Alternatively, use T4 to generate the code for you and turn it into a partial class. Anything to avoid duplicating like that....

View answer
Calculating and displaying score statistics using C# 6.0 features
Accepted answer
12 votes

I prefer to use explicit access modifiers -- it keeps everything uniform: you have internal int[][] JaggedArray so I'd make the others like _minV explicitly private. Every field that is outside-world ...

View answer
Putting everything in its place
8 votes

While reading my code for the bazillionth time, I noticed a logical error which would make it possible for very specific exotic scenarios to pop this up expectedly. At the very start of the analyzer ...

View answer
Simple Google ReCaptcha validation
Accepted answer
10 votes

private readonly string _ReCaptchaSecret; private readonly string _ReCaptchaSiteKey; private fields are either lowerCamelCase or _lowerCamelCase, both conventions are common. public ...

View answer
Injecting JavaScript to website for ordering products
8 votes

Alright, let's go through the code top-to-bottom. using Brushes = System.Windows.Media.Brushes; using SystemFonts = System.Windows.SystemFonts; Any particular reason you're using this alias? Most ...

View answer
Store open days and times
2 votes

You're interested in a Dictionary<DayOfWeek, StoreTimes>() which, coincidentally, actually inherits from IEnumerable<KeyValuePair<TKey, TValue>>. Additionally I would also suggest ...

View answer
Pagination implementation for a blog system
Accepted answer
8 votes

int num What does num represent exactly? Number of pages? Number of posts per page? Current page number? Properly naming the variable would help a lot in clarity here. var postsPerPage = 3; Turn it ...

View answer
Educational website using ASP.NET webforms
Accepted answer
7 votes

private class Comp_CatName_D : IComparer { public int Compare(object x, object y) { BusinessLayer.Cat_Table Cat_Table1 = (BusinessLayer.Cat_Table)x; BusinessLayer.Cat_Table ...

View answer
Understanding my permalink service tests
Accepted answer
4 votes

You're right, we can clean things up a little bit. First of all the method naming: I like to use a schema which tells me the unit under test, the scenario I test and the expected outcome. More ...

View answer
Checking if 3 numbers are an arithmetic progression
8 votes

InOrderEqual() Methods should express an action or a state, this doesn't do that. How about.. VerifyOrder? Or IsInOrder? InOrderEqual(2, 5 , 11, false) I would suggest using a named argument for ...

View answer
Getting a substring of a delimited string
Accepted answer
8 votes

Yes, you can definitely simplify this. public string GetSubstring(string input, int count, char delimiter) { return string.Join(delimiter.ToString(), input.Split(delimiter)...

View answer
CC C# calculator
Accepted answer
11 votes

How do you even use this code? You read through 5 different methods, each doing something specific -- How do you determine which one is used? The RemoveAll extension is expensive: you're creating a ...

View answer
Get list of files in directory with exclude option
Accepted answer
6 votes

You're already returning an IEnumerable<T> so you might as well turn it into an iterator block. Discard the local resultFiles and simply use yield return filename. MSDN on yield I don't like ...

View answer
Function that convert decimal to binary
Accepted answer
19 votes

One major improvement would be to just use what is supplied through .NET: Convert.ToString(int, 2); where int is your supplied argument. Convert.ToString Method (Int32, Int32) Converts the value ...

View answer
Getting a single value from the DB
Accepted answer
3 votes

public static String GetConnectionString() You shouldn't have to use this outside of the class so make it private. Furthermore I would turn it into a property and set it from the static constructor --...

View answer
C# Chat - Part 2: Client
Accepted answer
2 votes

private static bool FirstRun = true; private fields are lowerCamelCase or _lowerCamelCase, the latter receiving much preference. if (args.Length == 1 && args[0] == "--debug") This is fine ...

View answer
Array of immutable objects initialized at compile-time
Accepted answer
4 votes

I would suggest an enum: they're made to encapsulate a set of distinct values known at compile time. For example, this might be the code you have as a result: public enum CameraInformation { ...

View answer
Simplifying asynchronous "executeAsync" method along with "onFailure" callback
5 votes

If I'm having the logic correctly, I believe you can move from this: if (remoteFlag && secondaryFlag) { hostnames.add(localPrimaryHostname); hostnames.add(localSecondaryHostname); ...

View answer
Unit Tests for getting the first Monday of the month
Accepted answer
4 votes

public bool CheckSendNewEvent() { var now = DateTime.Now; const int SendTime = 8; var firstMonday = GetFirstMondayofMonth(now); var timeToSendOnFirstMonday = new DateTime(firstMonday....

View answer
1
2 3 4 5