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.

Filter by
Sorted by
Tagged with
8
votes
2answers
142 views

Non-Entity framework database interaction model

A C# WPF user interface has been developed for the Book Inventory MySQL database previously shown in this question. Since the database had already been developed this was a database first ...
8
votes
1answer
427 views

SalesTax problem (C# version)

One year ago I published an F# solution of the same task and there is an old C# solution. But I think it's a simple task and require a simple solution. What do you think? ...
8
votes
2answers
959 views

Sieve of Eratosthenes implementation is running slowly

I have written this code to find prime numbers, and it works well, but the calculation speeds are incredibly slow. Am I doing this wrong? I know that I might be really doing this the wrong way, but ...
7
votes
4answers
253 views

IPv4 struct utilizing explicit layout

I was inspired by Processing a list to build an IP in String Format to reinvent the wheel a little bit and play around with explicit struct layouts. You see, an IP address is really made up of four,...
7
votes
1answer
148 views

HTML-rendering framework for emails

Sometimes I need to auto-generate html-emails. To make this task a little bit easier I created a simple framework that takes care of rendering HTML. Because I'm mainly interested in generating HTML ...
6
votes
1answer
499 views

Shuffling an arbitrary list or sequence

After reading this question I wanted to write a short example of how a list or sequence could be shuffled in .net. The result turned out to not be very short: Program.cs ...
6
votes
4answers
1k views

Beginnings of a Poker hand classifier

For practicing/learning object orientation, I made a Card class and am practicing doing stuff with it such as shuffling decks and dealing hands etc... I have a ...
6
votes
4answers
1k views

Threshing: Sieve of Eratosthenes

I would like a complete threshing of this code so that I can see what I did wrong and what I am using incorrectly. I made this super simple, trying to learn a little bit about ...
6
votes
3answers
4k views

Building tree structure based on flat objects

You can find here a Follow-up question Description A List<UnrelatedObects> is returned by a 3rd party webservice, which will then be transformed to a ...
6
votes
1answer
274 views

Blockchain implementation in F#: Block and Blockchain

Some time ago I started writing a blockchain implementation for learning purposes. I used this article as reference. Originally I wrote the code in C# but recently I have rewritten everything to F#. ...
6
votes
1answer
98 views

Validating a StreamingPin

Recently I was thinking about the keyless entry on my car and how simple it has to be, so I wrote a C# programme to validate a StreamingPin, that is, a pin that is ...
6
votes
2answers
192 views

Reversing a Matrix

I took the idea from Reversing a matrix in C# and decided to write my own matrix-reversing code. Is there anything that I can do to make it even better? ...
5
votes
4answers
7k views

Implemenation for concurrent file access (read/write)

I am developing an application that works with files and folder on a network share (similar to the windows explorer). The application is used by multiple users and provides some commands for modifying ...
5
votes
2answers
6k views

Read binary serial data and parse integers

I'm reading serial data in binary format from a stream, and I'm not happy with how I extract the data because it takes so much operations to extract the binary data from a simple line of binary data. ...
5
votes
2answers
687 views

Visit each HTML element and apply inline CSS

I need to apply some css styles to an IMarkupElement. The generated HTML is only for emails so all styles are inline styles and the selectors are very simple, just ...
5
votes
1answer
581 views

Refactoring away from exceptions

What do you use for refactoring away from exceptions while programming functional in C#? I defined this class to hold function outcome: ...
5
votes
3answers
434 views

Class simulating a circuit pin

This class is the first of an open source project I just (a couple of days ago) started. The projects is meant to simulate circuits (logic gates and stuff) and this class is meant to manage pins. I'm ...
5
votes
3answers
6k views

Split the array so that the sum of the numbers on one side of the split equals the sum of the numbers on the other side

I would really appreciate if you can help me to find a better way to do it. ...
5
votes
1answer
190 views

Testing the process of assigning offers to a customer

I asked a similar question yesterday, which was criticised because I posted the test without the supporting code. Therefore I deleted the question yesterday as it was not clear enough. I am now ...
4
votes
2answers
91 views

Shoot the Messenger pt. 2

This is a follow up to Messenger supporting notifications and requests I've written a lightweight (I think) class that acts as a messenger service between classes for both notifications (fire and ...
4
votes
2answers
3k views

Make change for a given amount given denominations

Make change like at a cash register Input is the denominations of the currency and the sum In test case only coins are entered Return how many of each denomination Return the fewest possible ...
4
votes
1answer
421 views

Correct MVVM format

I have a Windows-Runtime app (very similar to WPF), and I am using (at least I think I am!) the MVVM style. I want to make sure I am doing this the proper way, and not just a working way. This is my ...
4
votes
3answers
1k views

(Re)Creating a tree from a flat collection (or “unflatten” a tree)

I need to create a tree from a flat collection. The order of elements is defined in a specification so it's rather impossible that it will ever change... but I want the whole algorithm to be ...
4
votes
1answer
67 views

Preparing tabular data to be sent as json

I query a database and pass the data for processing as a DataTable. After all computations (grouping, filtering, formatting etc.) I need to send it to a Web-Service ...
4
votes
2answers
624 views

Scheduler built with observables

I sometimes have to schedule some tasks and wanted to have my own reusable scheduler. Since I like the Rx, I build it on top of it. Follow-up There is a newer version of the ...
3
votes
1answer
174 views

SqlServer database reflection and autogenerating NLog.xml

This is my first attempt at using T4 templates and I thought I generate the NLog.xml with it by getting the tables and the columns from the database to ...
3
votes
2answers
71 views

Linked list implementation along with unit test - Round 2

Here is the link to the next round of code review: Linked list implementation along with unit test [Round 3] Here's the link to the previous code review: Linked list implementation along with unit ...
3
votes
2answers
417 views

Countable and uncountable sets in .NET (IEnumerable and Predicate)

There is a full featured support of countable sets in .NET: IEnumerable<T>. What about uncountable sets; sets defined by predicate? How can they be ...
3
votes
1answer
121 views

Class simulating a circuit pin (follow-up)

In a previous post I asked for a review on some code I wrote for an open-source project of mine. After the review I made some changes and I wanted to ask you for another round. This time I'm not ...
3
votes
2answers
985 views

Stop Watch application

I've done the difficult dailyprogrammer challenge #2: Your mission is to create a stopwatch program. this program should have start, stop, and lap options, and it should write out to a file to be ...
3
votes
2answers
629 views

Building tree structure based on flat objects - follow up

This is a follow up on this question and has now a follow up question here. I have implemented some changes to the class below and also added the method ...
2
votes
3answers
733 views

Compiling and throwing simple dynamic exceptions at runtime

I often need a simple exception with a meaningful name and some helpful message which usually just looks like this one: ...
2
votes
1answer
351 views

Guess a number between 1 and 100 (revision 1)

I have taken the critiques from the original post and tried to refactor. I used int.TryParse and that cleaned up quite nicely. What can I further improve on? Edit: (Guess a number between 1 and 100 (...
2
votes
1answer
157 views

Date only limited function class

Per the title date only class (or struct?). .NET does not offer a date only data type. I get there is time zone dynamic but then you have daylight-savings that can still kill you. I do document ...
2
votes
2answers
70 views

Creating keys/names from interfaces to avoid strings

There are many APIs that require some kind of a string key/name. I usually try to avoid using raw strings and prefer to use ...
2
votes
1answer
114 views

Growing potatoes in delayed sequences

In order to grow potatoes I'm implementing the retry pattern. If I fail to grow them, I'd like to try it again later. The first part I've implemented is a collection of delay generators. Their base ...
2
votes
1answer
72 views

Codility Cyclic rotation in C#

I'm learning C#, I programmed some things in java, and I would like to have a feedback on my C# code. The exercise is from codility. The goal is to rotate array ...
2
votes
2answers
385 views

Console single player blackjack versus a dealer again

This is the second pass on this. pass one A single player versus a dealer. It does not perform bets - it only track wins and losses and has no splitting. Other than that I tried to get it all in. I ...
2
votes
1answer
534 views

Type converter framework (v2)

This is the second version of my type converter framework. The the previous one can be found here: Type creator service & framework In this version I mostly implemented what @Dmitry Nogin ...
1
vote
2answers
104 views

Using Specs when testing the process of assigning offers to a customer

I am trying to spruce up my BDD skills using Specflow and Gherkin. Please see the classes below: ...
1
vote
1answer
139 views

Boggle using Trie and DFS

I already mentioned in my previous code review, there are two solutions for this problem https://www.geeksforgeeks.org/boggle-find-possible-words-board-characters/ this is the first: Find all ...
1
vote
1answer
337 views

How to add a random feature for a factory design

I'm creating a factory design for math problems. The purpose of the factory is: The problems must be generated with a certain difficulty (or level). To do this, I'...
-1
votes
1answer
140 views

Optimize finding GCD of all pairs of divisors

I've come up with a solution for Euler Problem 530, but my code runs too slowly to actually get the answer (solving for 10^15). What can I do to optimize it to run faster? ...
186
votes
4answers
30k 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 ...
229
votes
14answers
38k 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 ...
45
votes
3answers
91k views

Repository/Service Design Pattern

I use the Repository/Service design pattern in my projects and I have found something that might be a bit redundant. Am I writing any unnecessary code? With that in mind, here is my structure: <...
73
votes
16answers
5k views

BOOL×BOOL→ENUM mapping

Does this part look clean enough? Any suggestions on how to make it cleaner? ...
29
votes
1answer
25k views

Single-instance WPF application

This is the code I implemented so far to create a single instance WPF application: ...
49
votes
1answer
66k 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: ...
38
votes
2answers
3k views

KISS my… unit of work

I've seen many, many UoW+Repository implementations. Whenever one was built on top of Entity Framework, I'd cringe at the added complexity. Sure the complexity buys you (sometimes) full decoupling ...