Questions tagged [.net]

.NET is a software framework supporting a multi-language paradigm and supporting language interoperability. .NET applications are executed in a virtual machine (CLR) which provides a few important services: security, memory management and exception handling.

Filter by
Sorted by
Tagged with
40 votes
3 answers
11k 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 ...
JonathanPeel's user avatar
3 votes
2 answers
236 views

Calculator Program improvements

I'm pretty new to programming and made a few programs so far. I recently made a Calculator program and I hope you guys could tell me what I could do to improve. ...
the 's user avatar
  • 49
16 votes
4 answers
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. ...
Evan L's user avatar
  • 291
14 votes
7 answers
47k 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 ...
Idothisallday's user avatar
8 votes
2 answers
215 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 ...
pacmaninbw's user avatar
  • 23.8k
8 votes
3 answers
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 ...
aaronmallen's user avatar
6 votes
1 answer
119 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 ...
Der Kommissar's user avatar
6 votes
2 answers
790 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 ...
ChrisWue's user avatar
  • 20.3k
6 votes
2 answers
4k 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 ...
Denis's user avatar
  • 8,458
4 votes
2 answers
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 ...
paparazzo's user avatar
  • 5,976
3 votes
4 answers
2k 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 ...
paparazzo's user avatar
  • 5,976
2 votes
1 answer
207 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 ...
paparazzo's user avatar
  • 5,976
2 votes
2 answers
559 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 ...
paparazzo's user avatar
  • 5,976
45 votes
3 answers
6k views

Benchmarking things in C#

I needed a better way to benchmark code, because, well, rewriting the same benchmarking code every time I need it is just...well...unpleasant. So, here's a class which does just that, it runs an <...
Der Kommissar's user avatar
29 votes
5 answers
51k views

Type-safe Dictionary for various types

Assume the following situation: you have an object that can store any object based on a key (basically, IDictionary<string, object>). You want to store ...
svick's user avatar
  • 24.3k
19 votes
2 answers
1k views

Enforcing string validity with the C# type system

One of my biggest complaints about .NET is that there's no way to guarantee a string match a certain type in the type-system. Note This started as more of a proof-of-concept than a real usable system,...
Der Kommissar's user avatar
16 votes
6 answers
18k views

Determine if an image is opaque or transparent

I wrote an extension method defined for the Image Class (System.Drawing) — which returns a Boolean value telling you if the image is opaque or transparent. The color of each pixel in the image is ...
Owen's user avatar
  • 1,494
16 votes
4 answers
585 views

Entities and the things they do

So I have an Entity, which is responsible for providing an abstract base for other objects to inherit. (Like Actor objects, ...
Der Kommissar's user avatar
14 votes
3 answers
23k views

Timing out a method

I have created this extension method that can be used to run a function with a timeout applied to it. Is this a sensible way of doing it? ...
Rob White's user avatar
  • 281
14 votes
7 answers
1k views

Binary Heap where a comparison delegate is used

I currently have a Generic Implementation of a BinaryHeap. It must be able to maintain it's integrity with elements that may or may not implement ...
BarelyTilted's user avatar
12 votes
1 answer
191 views

RPSLSMB OOP Version 2

Rock Paper Lizard Spock Monkey Banana My original post Based off of Malachi's post I've changed the way rules work in this version to allow ties to result in double loss or double win. While ...
BenVlodgi's user avatar
  • 4,278
12 votes
5 answers
12k views

Validation that also returns error messages

My Create, Update and Delete methods should return a ...
Coder Absolute's user avatar
12 votes
3 answers
16k views

Extension method replacing elements from an IEnumerable<T> collection

Today I needed a method to replace all 'x' values in a said collection. Since there is no such method by default in .NET I wrote my own: ...
Denis's user avatar
  • 8,458
12 votes
2 answers
1k views

Implementing Dynamic Network Message Handling

I'm trying to handle network messages in a dynamic, and effective way, though I feel I've overthought it again. As of now, I have a very structured approach, but it feels as if it's a lot of overhead ...
Der Kommissar's user avatar
11 votes
4 answers
51k views

Converting the DateTime to and from Unix epoch times

I'm currently working on a thing I needed this feature for. Essentially, these are two methods to convert DateTime objects to and from the Unix epoch time (two ...
Der Kommissar's user avatar
11 votes
2 answers
3k views

BinaryTree<T> written in C#

I've written a binary-tree using .NET Core 3.0. What can I do to improve my coding style? ...
TheRealVira's user avatar
10 votes
3 answers
596 views

Google reCAPTCHA Validator: Iteration III

This is the third iteration of my reCAPTCHA validator. Iteration II can be found at: Google reCAPTCHA Validator: Iteration II It does almost everything required to do reCAPTCHA validation on anything ...
Der Kommissar's user avatar
10 votes
3 answers
8k views

Generate cryptographically secure random numbers in a specific range

A project I'm working on requires generating a random number of \$N\$ length to a very high degree of fair distribution between digits \$[0, 9]\$. That said, I used the ...
Der Kommissar's user avatar
10 votes
2 answers
3k views

Set desktop background

I created a simple program that downloads an image (different image every day), then sets it as my desktop background. I feel like the lines of code can be cut down significantly while still remaining ...
Josue Espinosa's user avatar
10 votes
5 answers
2k views

Using TryXXX pattern to avoid exceptions

I have been using the TryXXX and GetXXX pattern lately to give clients a choice whether to trap an exception or to read a boolean. An example of this concept would be ...
Mike's user avatar
  • 243
9 votes
3 answers
2k views

Wrapping COM objects with IDisposable

One of the things believed to contribute to destabilizing Rubberduck 2.x, is the fact that a lot of COM object references are stored in many places, and ...
Mathieu Guindon's user avatar
8 votes
1 answer
6k views

Implementation of the FNV-1a hash algorithm for 32- and 64-bit

Are there any improvements to these two classes which implement FNV-1a for hashing? Particularly, I'm looking for any reuse opportunities (possibly via a common abstract superclass derived from ...
Jesse C. Slicer's user avatar
8 votes
5 answers
7k views

Removing exact instances of elements in one list from another

Basically, here's the problem statement: Given an IEnumerable<T> source and an IEnumerable<T> exceptions, return ...
Der Kommissar's user avatar
8 votes
3 answers
756 views

MIST - auto-implemented, attribute-driven .NET notification mechanism

I have a component that I've used myself for quite some time, the short story is that it automagically implements a property change notification mechanism (very useful for implementing ...
Mik3c's user avatar
  • 101
8 votes
3 answers
4k views

Elevator Interview Problem OOP - Revised

Elevator program code challenge, revised: Can someone please critique my Elevator problem - I wanted to use OOP principles and coding standards. Also, does logic make sense? ...
BobSwanson's user avatar
8 votes
3 answers
212 views

RPSLS refactored to Object Oriented

I wrote a couple reviews for this CR post. In my most recent review, I refactored @Malachi 's code to fit OO design. I'm looking for any advice/hints/criticisms on it. A review is welcome for both ...
BenVlodgi's user avatar
  • 4,278
8 votes
3 answers
5k views

Format a timespan with up to two fields

I'm looking to achieve a time format that looks like this: 2d 4h remaining; or 1h 36m remaining; or 35s remaining, etc. So that it only displays the two largest values of time (this is how Clash of ...
Essential's user avatar
  • 255
7 votes
1 answer
6k views

Serializing objects to delimited files

For a new project I'm going to need to be able to serialize random types to TSV or CSV files, so I write a class which can be used to serialize any object to a TSV, CSV or any other _SV file you can ...
Der Kommissar's user avatar
7 votes
2 answers
764 views

Proper handling of exceptions in MVP

In my DAL currently I'm handling exceptions as follows. Is it in an acceptable level? Note : I'm using MVP in this Winforms application. ...
CAD's user avatar
  • 1,753
7 votes
1 answer
386 views

AutoResetEventAsync, am I missing something?

So I wrote an asynchronous version of AutoResetEvent: ...
SHSE's user avatar
  • 223
7 votes
3 answers
600 views

Secure password hashing implementation

I'm implementing a password hashing method for a website. The code below is part of the User class. Any pointers on what I could do better? ...
Mike D.'s user avatar
  • 252
7 votes
1 answer
9k views

Removing accents from certain characters

I have a method that I am using to remove accents from certain characters. The problem is the massive slew of characters I am expected to work with. I have to, basically, remove accents from all Latin ...
Der Kommissar's user avatar
7 votes
4 answers
3k views

Function for formatting a timespan with optional trailing zero

I'm looking to achieve a time format that looks like this: 2d 4h remaining; or 1h 36m remaining; or 35s remaining, etc. So that it only displays the two largest values of time (this is how Clash of ...
Essential's user avatar
  • 255
7 votes
1 answer
107 views

Streaming a Pin functionally(ish)

Earlier today I wrote a question (Validating a StreamingPin) and I thought it was a good idea (apparently I was the only one who thought so, but whatever), so I proceeded further with it and developed ...
Der Kommissar's user avatar
6 votes
2 answers
9k views

Database access class

I'm looking for any comments or feedback on my database access class. Security and speed are two things I'm most concerned about. One thing to note is this class has to work in a C# .NET 2 ...
Justin808's user avatar
  • 775
6 votes
2 answers
2k views

Web API using Repository / UnitOfWork

I'm looking for feedback on a repository I set up based on a blog post I read here. I have just recently got more into .NET within the past year, so any feedback and/or best practices that can be ...
Scott Smith's user avatar
6 votes
1 answer
72 views

Analyzing spoke overlaps during rotation

For a personal project that I've recently started I have to analyze the rotation of two shapes with sets of spokes, where the spokes are evenly-spaced, and split into a given number. That is, if I ...
Der Kommissar's user avatar
6 votes
1 answer
379 views

Flexible socket framework

I'm working on an async socket server, would really appreciate any critique and some advices regarding the place where i process received messages. My interfaces are as follows: IAsyncClient <...
HardLuck's user avatar
  • 175
6 votes
1 answer
225 views

Processing input in background while user is typing

Use case A GUI with 2 controls: An input control for text (a DNA sequence) that should be analyzed A result control that displays the analyzing result of the entered text The analysis takes 2-3 ...
JanDotNet's user avatar
  • 8,538
6 votes
4 answers
2k views

Conversion helper with support for enumerations and Nullable<T>

I recently wrote this code as a more versatile stand-in for Convert.ChangeType. I have a nagging feeling that there's something I might be overlooking, or that ...
Patrick's user avatar
  • 263