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
9
votes
3answers
21k views

Generic advanced Delegate.CreateDelegate using expression trees

As far as I know the standard Delegate.CreateDelegate() which allows to create a delegate by using reflection, doesn't allow doing something as follows when the ...
8
votes
3answers
10k views

Make WCF Service testable

I have WCF Service. It works fine and I want to have test coverage for it. Unit tests and acceptance. The problem is the static class in the code. How is it ...
7
votes
2answers
11k views

Send messages in TCP-based communication system

I am working on a TCP-based Communication System. I wrote a working function for sending Textmessages and remotely opening a MessageBox. I would like to know how ...
11
votes
4answers
9k views

Finding the first duplicate in an array

My code returns the correct answer the first duplicate is 3 (represented as int f) . I am struggling finding a more efficient way to find the first duplicate? My ...
12
votes
3answers
473 views

RPSLS is less messy now, but is it clean?

This is a follow up to the following questions: RPSLS Game in C# Ensuring user input is an integer in a range I haven't made my way to DecideWinner() yet, but ...
11
votes
2answers
1k views

Rock-Paper-Scissors-Lizard-Spock Challenge, take 2

This post is following-up on Rock-Paper-Scissors-Lizard-Spock Challenge I had a gut feeling that I was somehow abusing IComparable<T>, @svick's answer ...
11
votes
3answers
5k views

WinForms dice roller

I am writing a dice roller winforms application using C# 2012 VS. Dice roller is set up for playing Shadowrun tabletop. I feel that there might be too much code going into the GUI, but I am unsure ...
7
votes
4answers
5k views

Hacker Rank - Poisonous Plants

I have the solution for the problem, but it is taking me 7 seconds to run on a large dataset. I am trying figure out a better way of doing this. It has to run in under 3 seconds. Problem Statement: ...
6
votes
1answer
245 views

Console-based BlackJack in C# - Follow-Up

I have done some code-refactoring of my console-based BlackJack in C#. Finally found a better solution to solve Ace problems (double Aces should be value 22 and third Ace should be value 1). I still ...
6
votes
2answers
1k views

Google reCAPTCHA Validator: Iteration II

This is a follow-up to the other post I made (less than an hour ago) about my Google reCAPTCHA C# implementation: Google reCAPTCHA Validator This adds support for error messages, so that you can ...
15
votes
2answers
3k views

A completely overkill BrainFuck lexer/parser

I'll need to build a syntax tree (AST) for Rubberduck, but since VBA has dozens of tokens and complex rules, I needed a simpler language to play with first, so I thought BrainFuck would be a perfect ...
14
votes
7answers
42k views

Regex validation for Email Address

I need to validate whether my regex is correct for below scenario. Suggestion's if the regex is correct: Wiki Link Local_part The local-part of the email address may use any of these ASCII ...
11
votes
3answers
570 views

Multithreaded Mandelbrot Generator Ver 2

Update: Version 3 is here. My first version was an answer I provided to EBrown for his original post titled "Multithreaded Mandelbrot Generator". My answer had many good things in it, but I felt ...
10
votes
5answers
2k views

Beginnings of a Poker hand classifier part 2

Part 1 - Beginnings of a Poker hand classifier I'm a beginner programmer I've been working on a poker hand classifier to improve my object orientation and programming skills, I've improved and ...
9
votes
2answers
2k views

Item-level locks for a large number of items

Background I'm working on a system that records information about a large number of external documents. These documents are organized by "repository". There can be a modest number of repositories (...
7
votes
1answer
6k views

Hypothetical SalesTax challenge

I have a small solution to the following hypothetical problem: Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty ...
7
votes
4answers
14k views

MinHeap implementation

Please comment on this. ...
6
votes
2answers
884 views

Named string interpolation

On machines where I don't have C# 6 I use this named string interpolation method. I tried to make it as pretty a possible as far as good coding practices are concerned but I just can't get rid of the ...
4
votes
2answers
206 views

Binary protocol variability V2.0

Up-to-date Version of this question: Binary protocol variability V3.0 Summary of the problem: Parsing an incoming stream of events from a binary communication protocol, if we have some variations in ...
3
votes
2answers
1k views

Create database connection and run the insert, delete, update queries class

Recently while developing our demo project I had to a write a lot of repetitive code for executing the database queries (insert, update, delete). So, I have put all the repetitive code into a class ...
3
votes
4answers
2k views

Summing up distinct elements in steps

My current task is to find a score from an array where the highest/lowest scores have been taken away, and if the highest/lowest occur more than once (ONLY if they occur more than once), one of them ...
21
votes
3answers
458 views

Rubberduck's “Extract Method” refactoring implementation

With the ANTLR-powered parser, I was able to reimplement all code inspections from the last release build, and the rest of the inspections on the road map are now implementable. Code inspections and ...
12
votes
5answers
7k views

Simple binary heap in C#

I've written a simple binary heap in C# and I want to know if it has any problems or if I can make it better. ...
12
votes
3answers
1k views

Does everyone still love Fibonacci?

I'm following up on this question. I made a few decisions about my model and implemented recommendations accordingly. TL;DR the link Uses a loop algorithm to return a Fibonacci number \$Fn\$ of ...
10
votes
3answers
817 views

Lvl 1 upgradeable attributes

I've built the groundwork for an attributes (as in Strength, Intelligence, not as in DebuggerHidden, TestMethod) framework for ...
10
votes
2answers
2k views

Will this Circuit Breaker catch fire?

I was going to post this code as an answer to a recent question, but I wrote this code a little while ago (like, a year ago; if I recall correctly I wrote this after reading this article) and I'd like ...
9
votes
4answers
4k views

Bisection method

Totally agree lack of { } on if else is bad practice. That is just how I roll and I can't do it at work. Use bisection to get to the index of a target value of a sorted array in O(sqrt(array....
9
votes
8answers
3k views

Temperature conversion application

I'm two months in a programming course and our instructor told us we should think about building real-world applications as to gain valuable experience. I got the idea of doing a simple temperature ...
8
votes
3answers
460 views

Multiple file access abstractions

When using dependency injection for nearly everything it's good to have some file access abstraction. I find the idea of ASP.NET Core FileProvider nice but not sufficient for my needs so inspired by ...
7
votes
3answers
1k views

Dataset with optional addition to where statement

I am trying to generate a dataset from a query that has a where statement. If the user passes a value additional things need to be added to the ...
7
votes
1answer
2k views

Waiting for a lock to release with ManualResetEvent and Quartz

Follow-up to: Waiting for a lock to release with Thread.Sleep()? I've found the time I tried to rewrite my WaitForLock-Method to utilize the Quartz.NET Scheduler ...
7
votes
2answers
680 views

Initializaing and running Console application

In most of my applications I think my core code is quite good organized and uses only dependency injection for everything. However as far as the initiailzation is concerned I find it's a huge chaos ...
6
votes
2answers
200 views

Codility's Permutation Check in C#

I've made a few things in Java, and now I'm learning C#. The code passes the tests with 100% final score. I want to know what things can be improved in my code. Task description A non-empty ...
6
votes
2answers
570 views

Buffering of fast changing datapoints or events

The following class implements a buffer which captures fast changing datapoints or frequently raised events and dispatches them in batches. It will asynchronously call a processing function for the ...
5
votes
1answer
709 views

Making TypeNameHandling in json.net more convenient

Handling abstract types in json.net can be sometimes challenging because it requires a very long and complex syntax like: ...
5
votes
1answer
172 views

Setting up keyboard bindings using JSON and reflection

My game uses configuration files in JSON format. One of them is used for setting up control bindings, and it looks like this: ...
5
votes
2answers
1k views

Custom enumeration classes

Lately I've been using a lot of enums in my project and the lack of generic Enum constraint seems to be quite problematic. This combined with few other headaches ...
5
votes
2answers
1k views

Prime Number Speed

I know prime number programs have been beaten to death. I have been programming for eight years (not that long, but I'm not in my 20s yet and I got a programming job straight out of high school so I'm ...
4
votes
1answer
3k views

Concurrent/parallel ForEachAsync - proper handling of exceptions and cancellations

I've created an asynchronous parallel ForEach mechanism so I could enumerate an enumerable by N degrees of concurrency and process an action for each item. ...
4
votes
3answers
1k views

Using the observer pattern with collision detection

My Game class has a property of type Player, which inherits from Entity: player = new Player( "knight.png" ); It also has a property of type World, which has a ...
3
votes
4answers
1k views

Poker Hand Evaluator

Poker is 52 cards - 4 suite and 13 rank: Hand is exaclty 5 cards Order of hands Straight-flush - all same suite and in order Quad four of same rank Boat three of one rank and two of another rank ...
3
votes
2answers
219 views

RFC 1951 “Deflate” compression

This is a little project I did over Christmas, I wanted to understand a bit more about how RFC 1951 (https://www.ietf.org/rfc/rfc1951.txt) compression worked, mostly out of curiosity really. RFC 1951 ...
3
votes
1answer
2k views

Creating a concurrent/parallel ForEachAsync that can fail immediately or wait until enumeration is complete

I needed an asynchronous parallel ForEach mechanism so I could enumerate an enumerable by N degrees of concurrency and process an action for each item. Searching ...
2
votes
2answers
79 views

Logger adapter with a configurable chain of responsibility of middlewares

I use my own logger adapter that collects data into a dictionary: public class Log : Dictionary<string, object> { } This is really all I have. I then pass ...
1
vote
2answers
651 views

Project Euler #3 solution

I'm trying to solve Project Euler problem #3, which asks: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? Can you please review the ...
12
votes
4answers
3k views

Type system for different representations of angle value

I want to implement a Type system for different representations of an angle value. Motivation to implement this as a type system comes from this question. Angle can be represented using the ...
11
votes
3answers
6k views

Waiting for a lock to release with Thread.Sleep()?

There's a follow-up: Waiting for a lock to release with ManualResetEvent and Quartz. I've written a simple Lock-Mechanism which is saving the states of the locks in a database. Now I need to wait for ...
10
votes
2answers
195 views

Html rendering framework with dynamics

I came to the conclusion that the previous framework was too complicated and not easily extendable so I tried it again but this time with dynamics. It's much much shorter and I think it's much easier ...
10
votes
2answers
172 views

Of Procedures and Variables: never enough nodes

Building on my ANTLR tree listener, I'm now starting to see how the whole thing is coming together. As I proceed to implement the numerous Node classes I'm going ...
9
votes
1answer
1k views

Sieve32Fast - A very fast, memory efficient, multi-threaded Sieve of Eratosthenes

An improved version Sieve32FastV2 is available. The classical solutions for the Sieve of Eratosthenes fall into 2 camps: one uses a bool[], which is fast but very ...