We’re rewarding the question askers & reputations are being recalculated! Read more.

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
76
votes
5answers
23k 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 ...
18
votes
4answers
20k views

Split a string into chunks of the same length

Inspired by this question in chat Is there an easy way in .NET to split a string into an array by pulling chunks of the text in. I.e. I have an 18 character string I would like in 3 6-character ...
14
votes
3answers
627 views

Sieve31, my sieve of Eratosthenes returning IEnumerable<int>

This very fast, simple sieve quickly finds 31 bit primes. It uses a memory efficient BitArray for odd numbers. How a 32 bit int...
17
votes
3answers
4k views

RPSLS Game in C#

I went with what I know and can use well, not what I know and can't figure the syntax out to make it look good. So please enjoy the code and prepare to school me (probably in the basics) in C# ...
5
votes
0answers
149 views

Scheduler built with observables v2 (follow-up)

It would probably be too easy if the old Scheduler worked as intended being that simple. But an eye-openig review showed that from time to time it'll miss one ...
39
votes
3answers
10k views

Exporting doc types using queues and multithreading

For a while I have been interested in seeing if some tasks work well when split across multiple threads. On the one project I have been busy with I have been creating a lot of small utility apps, to ...
22
votes
3answers
11k views

Returning status codes from business layer

This is what I've been doing so far in my business layer to return error messages to the user. ...
8
votes
6answers
11k views

Variable declaration closer to usage Vs Declaring at the top of Method [closed]

As part of our sprints, we do peer review each others code. Here is the code that I am reviewing. ...
10
votes
3answers
3k views

Converting between data and presentation types

Below is how I'm solving the problem of converting between data and presentation types, I'd like to know if that's a good way to go about it, and if not, what would be a better way to go about it. I ...
16
votes
8answers
4k views

Project Euler Problem #4 - Palindromic number

The problem is as follows: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made ...
11
votes
3answers
3k views

Initializing immutable objects with a nested builder

I need to initialize several parameters of an object but I also wanted to make it immutable. At the same time I don't want the constructor to take all several parameters because some of them are ...
8
votes
3answers
254 views

Toggle any application feature ON or OFF

When testing or debugging applications it'd be often useful to be able to run it without certain features like committing things to the database, saving files, sending emails, reading files, executing ...
6
votes
0answers
392 views

Sieve32FastV2 - A fast parallel Sieve of Eratosthenes

I’ve created a much cleaner, better designed version to my parallel sieve. I’ve implemented most of EBrown’s micro-optimizations but also revamped the code on my own (that is not in direct response ...
5
votes
1answer
275 views

PDF Script Tool - adds JavaScripts to PDF files

This is a Windows Forms application that adds JavaScripts to PDF files. It supports multiple files at the same time. Right now, the only supported script is a "time-stamp on print" script, but any ...
13
votes
4answers
1k views

Multithreaded Mandelbrot Generator

I built one of these long ago, and it got lost when I reformatted my SSD (sad day) so here is the new version. It is very multithreaded, spawning numCores - 1 ...
3
votes
1answer
216 views

Sieve32, a simple 32 bit sieve returning IEnumerable<uint> using C#

What a difference 1 bit makes! This very fast, simple sieve of Eratosthenes quickly finds 32 bit primes. It uses a memory efficient BitArray for odd numbers – but ...
67
votes
9answers
28k views

Implementing a Singleton pattern in C#

Is this the best way to implement this pattern in C#? ...
28
votes
3answers
1k views

A Failable<T> that allows safe returning of exceptions

This was inspired by a conversation in chat, that started with the discussion of C#7.0 tuples and out parameter declarations, which led to the idea that there is no 'good1' way to return an error ...
25
votes
2answers
4k views

Go on, mock my IDE

Because of the coupling with the VBIDE API (the extensibility library for the VBA IDE), unit testing the rubberduck refactorings, inspections and quick-fixes has been pretty much impossible, at least ...
10
votes
1answer
210 views

Linq-to-Sage Implementation

Following-up on my last question where I wrapped the Sage API with a familiar IRepository interface, I decided to push the abstraction a step further, and... ...
4
votes
1answer
634 views

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 forget updates to other classes) and requests (a notification sent out that ...
2
votes
1answer
235 views

Countable and uncountable sets in .NET (clean version)

Sorry, it used to be some retired garbage in Countable and uncountable sets. Now and here it is clean. P.S. I would not like to say that this stuff is about to replace functional programming :) No, ...
7
votes
3answers
413 views

RPSLS game revisited. Is my design better than previous attempts?

This question is a follow up to these questions: RPSLS Game in C# Ensuring user input is an integer in a range RPSLS is less messy now, but is it clean? Right now I have a couple of ideas in the ...
6
votes
2answers
134 views

Middleware for sending PartialViews via email

After all partial views are rendered and all styles are inlined my RESTful service is sending them via email. I implemented this feature with a MailerMiddleware. ...
4
votes
1answer
100 views

Replacing Uri with a more convenient class

I needed some data structure for holding Uris so I thought I try the Uri class. It quickly turned out that it's very impractical because: it's missing an implicit ...
1
vote
2answers
4k views

PDF Stamper Method to Add Field and Script to PDF File

This is related to my (unanswered) question here, but the code has changed considerably since I asked that question. I have a method that takes the filename of a PDF file and a Script object, and ...
19
votes
3answers
1k views

Who's using what where - turning code into symbols

The Rubberduck project is coming along pretty nicely, and for the next version the parsing strategy is getting yet another revision, and this time around it really feels like it's done right. Or is ...
6
votes
1answer
98 views

Generic container similar supporting PeekMax, PeekMin, Sum, and PeekNextToMax

I needed to implement a data structure that supports the following operations: create from an existing collection get the maximum item ("Alpha") get the nearest-to-maximum item ("Beta") get the ...
6
votes
3answers
406 views

Next Instance of DRY Refactoring

I'd like some additional assistance on refactoring. This is my latest update for this iteration. ...
5
votes
0answers
175 views

Chaining JSON transformations with visitors

I have currently two use-cases that require JSON transformations before it can be deserialized. The first use-case requires changing the custom short type property name from ...
5
votes
3answers
377 views

Should I refactor for DRY?

I'd like to get some input on whether or not to DRY up this code. And if so how to implement it correctly. How do I know when it's worth refactoring? ...
5
votes
4answers
595 views

Class Seperation vs Polymorphism

I'm interested in optimizing my code. Can someone help me understand the best way to trim this code down with DRY methodology? So I've got these two classes here preforming WMI queries on two ...
5
votes
4answers
2k views

Project Euler #5 - Lowest common multiple of 1 through 20

This is my code. All comments welcome. Last time run it only took 335 milliseconds: ...
5
votes
3answers
563 views

Console Application Customizer - GetBootstrap v2.0

GetBootstrap-2.0 update from GetBootstrap-1.0.0.2 I just update my console application customizer and add some new features like disable minimize, maximize and close button, new color and simple ...
4
votes
2answers
242 views

Genericizing PropertyValues

This should be the last iteration for this code. Does this approach make sense or am I heading down the wrong path? The only thing I can see to make this better is to genericize the ...
1
vote
0answers
35 views

Testing the process of assigning offers to a customer 2

I asked this question earlier: Testing the process of assigning offers to a customer. Following on from the answerers comprehensive response. I have attempted it again. Please see the test code ...
61
votes
4answers
55k 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 ...
96
votes
16answers
183k views

Generate random numbers without repetitions

I want to generate a list of N different random numbers: ...
45
votes
2answers
96k views

Unit of Work and Repository with Entity Framework 6

Based on the reply of this question I have created the following code. I need to check whether it's good or not. Here is my entity class: ...
54
votes
11answers
12k 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 ...
36
votes
3answers
9k views

Ensuring user input is an integer in a range

I have isolated a little bit of code that was causing a small debate between myself and another user. I have taken some of the things that he said and meshed it with the code that was being reviewed ...
41
votes
4answers
5k views

Rock-Paper-Scissors-Lizard-Spock Challenge

"Scissors cuts paper, paper covers rock, rock crushes lizard, lizard poisons Spock, Spock smashes scissors, scissors decapitate lizard, lizard eats paper, paper ...
33
votes
7answers
6k views

Project Euler #7 10001st prime

I decided to start working on the Euler project exercises. I'm doing fine for now but the seventh problem is running quite slow and I can't think of anything to make it work faster. It takes around ...
47
votes
2answers
69k 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 ...
17
votes
6answers
10k views

Simple object validator

I wrote a simple validation tool that allows me to quickly define validation rules and check my data objects against them. I know there is this another tool called FluentValidation but... I'm not a ...
15
votes
4answers
1k views

Is decoupling necessary for very small applications?

I threw together a small solution for my organization today for some basic data review and approval procedures. This particular application will likely not change or add functionality at any time. ...
39
votes
4answers
5k views

Everyone loves Fibonacci

I was bored and burnt out on more serious projects.... until I saw this Computerphile video on YouTube. Now I'm inspired again. Now I feel like spending some time implementing that recursive algorithm ...
29
votes
5answers
3k views

A completely repetitive console prompt, a completely repetitive console prompt

So I wrote this for my Mandelbrot Generator, to collect and use input from the user, and I made it dynamic enough to be useful anywhere. I'm really interested in all critiques of it, as I'm going to ...
29
votes
6answers
4k views

DailyProgrammer 284: Wandering Fingers

Description Software like Swype and SwiftKey lets smartphone users enter text by dragging their finger over the on-screen keyboard, rather than tapping on each letter. You'll be given ...
15
votes
3answers
26k views

Salt generation in C#

I have designed a small method to generate a salt for a password. All this does is create a random salt and does nothing to add it to the password. I have a few questions regarding my very simple ...