Magus
  • Member for 8 years
  • Last seen more than 2 years ago
Using composition instead of inheritance
1 votes

One simple thing you could do to make things simpler and less repetitive, while staying more in line with the idea of composition is this: public class AttachmentService { public IEntityBaseService&...

View answer
How can I make this StringToCollections method more generic?
4 votes

On Empty Strings In your question, you have a Where checking against an empty string. Strings are, in general, tricky to deal with. They might be null, or they might be empty, or they might have a ...

View answer
Applying a 'mean filter'
3 votes

I'm not going to try optimizing this. Right now, this code is ugly for other reasons. First and foremost being the naming: In C#, local variables should be camelCase and should generally not include ...

View answer
Populating values into a C# object
Accepted answer
6 votes

A few things straight away: You have a class called India which really just holds a collection of States. I would suggest not using that class at all, instead creating a List<State> States ...

View answer
Username and password creator
7 votes

First off, well done! Many first questions on this site don't even contain code which compiles! Now for the review: In C#, class names are expected to be in PascalCase. This helps your code look ...

View answer
Listing skills for role-playing characters
4 votes

The simplest method is to use the Dictionary<T, U> class. var skills = new Dictionary<SkillAttackType, List<AttackSkillData>>(); You can then simply do: skills[SkillAttackType....

View answer
Comparison between strings
11 votes

Anna Lear has pointed out flawlessly that CompareTo is meant for sorting and similar operations, rather than equality. In .NET, most of the time you can indeed get away with the standard == operator, ...

View answer
Making operations more dynamic
1 votes

After writing up a whole question about how to do this with your validation method, decided to scrap it and show you this: public static class Validation { public static bool Equal(object first, ...

View answer
WPF Calculator Code
4 votes

Commands In WPF, one very valuable property is the Command property. For instance: <Button x:Name="One" Content="1" HorizontalAlignment="Left" Height="20" Margin="10,40,0,0" ...

View answer
Threshing: Sieve of Eratosthenes
6 votes

Generally speaking, this seems fine. The main changes I'd make are to change the Int64 to long which has the same meaning, but is more comfortable for users of other languages. It's very rare to see ...

View answer
How to know when I need to use get/set and when not?
Accepted answer
3 votes

First of all, I'd make the texture and position fields private. They're set from the outside, and the outside doesn't need to change them. Then I'd extend that. Anything your class needs to be given, ...

View answer
Extension method to return a default value for any null value
5 votes

The biggest problem for me is that this is an extension method on System.Object and returns a dynamic. Because this is already generic on T, T can be inferred if used as the parameter and return type....

View answer
How should I structure my Unit tests for minimal Asserts?
Accepted answer
8 votes

In this case, what you're really trying to do is validate three MessageDays, as the return values of one method. As you are only testing one thing (the successful return of a method), you need not ...

View answer