Questions tagged [c#]
C# is a multi-paradigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform. Use this tag for questions related to C#. In case a specific version of the framework is used, you could also include that tag; for instance .net-2.0.
9,970 questions
258
votes
14
answers
54k
views
Calculating entropy of a string
We're calculating entropy of a string a few places in Stack Overflow as a signifier of low quality.
I whipped up this simple method which counts unique characters in a string, but it is quite ...
206
votes
5
answers
36k
views
Dijkstra path finding in C# is 15x slower than C++ version
I'm implementing Dijkstra's algorithm with a priority queue for a game I'm developing in Unity with C#. I was a bit disappointed with the performance, so I decided to port the code to C++ and see if ...
110
votes
16
answers
244k
views
Generate random numbers without repetitions
I want to generate a list of N different random numbers:
...
92
votes
9
answers
9k
views
Mutually exclusive properties
The question is probably quite simple, but I would like to hear what drawbacks we will have with our code.
So, we had a simple implementation and interface for it:
...
87
votes
5
answers
26k
views
SudokuSharp Solver with advanced features
Even though it's the first time I'm writing something this "big", it feels like I know C# quite well (it is very similar to Java after all). It's been nice to learn LINQ also and I am very impressed ...
82
votes
8
answers
227k
views
Getting/setting default values from my App.config
Imagine that I need a color palette for my Winforms application to have a consistent look.
What I did was create a static helper class and helper methods that I can call from anywhere in my code, and ...
79
votes
16
answers
6k
views
BOOL×BOOL→ENUM mapping
Does this part look clean enough? Any suggestions on how to make it cleaner?
...
70
votes
4
answers
59k
views
EF Code First with Repository, UnitOfWork and DbContextFactory
I am about to >explode< :) due to amount of reading on this subject...
My head hurts, and I need some honest opinions...
There is a similar question/review that I noticed, but I believe my approach ...
67
votes
9
answers
30k
views
Implementing a Singleton pattern in C#
Is this the best way to implement this pattern in C#?
...
61
votes
11
answers
14k
views
Sales tax calculator, rejected for being not OOP
I applied for an Application Developer position. They require all their applicants to complete 1 of 3 programming assignments. I picked one for sales tax calculation. It was quite simple.
Write ...
58
votes
4
answers
166k
views
Comma delimited string from list of items
Is there a simple way to create a comma delimited string from a list of items without adding an extra ", " to the end of the string?
I frequently need to take an ASP.NET CheckBoxList and format the ...
58
votes
1
answer
88k
views
Getting the value of a custom attribute from an enum
Suppose we have an enum called "Planet" and it has a custom attribute of class "PlanetAttr",
these methods will give you the attribute value for a given Planet value:
...
56
votes
3
answers
55k
views
Simplified secure encryption of a String
I have two code examples that I wrote for best practices encrypting a string that I'm looking for feedback both in terms of best practices and security. They are both using authenticated encryption. ...
55
votes
2
answers
89k
views
Single instance of reusable HttpClient
I've got this method and I realize that an instance of HttpClass is going to be created for each call to it. While working seemingly OK, I'm considering moving it ...
52
votes
7
answers
8k
views
RPG Currency System
I just spent the last few days constructing the currency system for my game, and was wondering if you guys had any suggestions on how—if at all—I could improve it. Before I show the code, let me ...