Jeroen Vannevel
  • Member for 9 years
  • Last seen more than a week ago
Single instance of reusable HttpClient
Accepted answer
58 votes

You don't need multiple instances. In fact, HttpClient is designed specifically to persist and be used for multiple requests (see: HttpClient.DefaultRequestHeaders). There's already a lot written ...

View answer
Generate random numbers without repetitions
40 votes

Yes, there definitely is. You generate a collection of elements, mash it around and start pulling items out of it. A quick oneliner would be: Enumerable.Range(0,100).OrderBy(x => Guid.NewGuid())....

View answer
Who is this Chatbot?
Accepted answer
23 votes

Your DynamicArray class is mimicking an ArrayList which is exactly that: a dynamic array. Use this instead of reinventing the wheel. Use break; instead of System.exit(0) to exit a loop. It leaves ...

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
Is wrapping exceptions good practice?
Accepted answer
19 votes

There is little reason to do this. If you include the stacktrace in your logs you already know where the problem exists; the only thing you'd miss is the input which you might know from different ...

View answer
The FizzBuzz challenge in Java 8 written in a short, readable and interesting way
Accepted answer
17 votes

A guideline that I use for deciding on a StringBuilder or not is that it depends on whether I know beforehand how many times it will be used or not. I believe I've come across this recommendation on ...

View answer
The Breakfast Club attendance
Accepted answer
16 votes

First a general remark: EWWW. You're creating HTML as a string and returning that to the client. That's not how we do it in a backend (at least, that what I assume I'm looking at). The proper approach ...

View answer
Find the number of working days between two dates inclusively
16 votes

Personally, I think your approach is very complicated for what it should be trying to do: loop over all days between the start and the end date and count how many of those are not in the weekend. ...

View answer
Send email just once per day
15 votes

Couple of remarks: IsSent() smells like a property, not a method. It should be more descriptive as well: what object are you calling this on? It seems to indicate Email.IsSent but that's not what ...

View answer
Writing better JUnit tests
Accepted answer
15 votes

A minor remark: your test is named testCreateNotExistingEmail. The @Test annotation already indicates that this is a test so it doesn't have to be repeated in the methodname itself. Adding to that: I ...

View answer
Validate and import data from an Excel file
14 votes

Concatenating strings Sometimes you use a StringBuilder and sometimes the compound assignment operator (+=). The key to distinguish when to use what is this: if you know the amount of concatenations ...

View answer
Finding average of eight immediate neighbors of a matrix
14 votes

Welcome to CodeReview! Class naming Maybe it's a term I'm not familiar with but Matrixer does not seem to ring a bell. Is it supposed to identify a "creator of matrixes"? Is it the name of your ...

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
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
Who's using what where - turning code into symbols
Accepted answer
12 votes

I can't see it because of some missing classes but are the types being returned also immutable? You've made types like Declaration nicely immutable but if the complex objects themselves are mutable ...

View answer
Customized Exception
12 votes

You're using ArrayList which is the weakly typed version of List<T>. Now, since apparently this is done because you're using object[], I would suggest to just strongly type this to List<...

View answer
Creating a grid in HTML from a database search
12 votes

Use string.Empty instead of "" to indicate an empty string. It conveys your intent without ambiguity (i.e.: nobody will think you forgot to enter something in the string). When concatenating in a ...

View answer
Simple Pong game
Accepted answer
12 votes

Glad to see you made it here. There is no predefined number of "this many arguments and no further" so it is a subjective decision. In my experience, I would say that as soon as you see more than 5 ...

View answer
Read and convert binary files to ASCII text
Accepted answer
12 votes

Aside from turning StringBuffer into StringBuilder, there are a few more things I'd like to note about your code. Compound assignment operator This line: lastString = lastString + line; Can be ...

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
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
MVC controller code
Accepted answer
11 votes

I'm not very familiar with JSP and EL (which isn't very good considering I have an exam on it in a few days), but in general Java terms you can simplify it a lot by moving the separate lists to a Map&...

View answer
Sudoku generator in Java
11 votes

Enums Your mins and maxes (and difficulties) are all over the place. Consider grouping them into an enum like this: public enum Difficulty { EASY(36, 49), MEDIUM(32, 35), HARD(22, 27); ...

View answer
Dynamically sorting with IComparer
Accepted answer
11 votes

CompareTo This public int CompareTo(ProductSortAttribute other) { if (this.Index == other.Index) { return 0; } if (this.Index > other.Index) { return 1; ...

View answer
Image handling class
11 votes

Glad to hear that you're looking for a review before publishing it! Let's get right to it. Class naming Your class is named Images but that doesn't convey a meaning to me. In fact, it's a plural so ...

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
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
Rubberduck's "Extract Method" refactoring implementation
Accepted answer
10 votes

Your GetParentMethodDeclarations() method has a lot of repeated code when it loops over the positionSelection collections. Considering all of them are the same, you can extract them to a helper method ...

View answer
Data Access Layer code for MSSQL Databases
10 votes

I will review the tests because they definitely need some work! GetDataTableTest() The Test suffix is redundant, they're all tests. What I want to know is what scenario is being tested when the test ...

View answer
1
2 3 4 5