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
12
votes
2answers
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 ...
12
votes
1answer
161 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 ...
11
votes
5answers
8k views

Nested if statements with 3 different parameters

I have a block of code below. The allDone() method at the bottom should only be run if the allCompleted == true. It should run ...
11
votes
5answers
7k views

Deep nesting when looping over an object model coming from a 3rd part

I am stuck with this horrible object model coming back from a 3rd party product. It's six levels of objects deep, and I have to loop through the collection in each level, to get the values I need, in ...
11
votes
5answers
2k views

Repetitive code driving me crazy!

Ok, So first I must say that everything I know about coding I have learned on my own in my spare time so bear with me if my code is primitive, but please, I am open to any comments to make me better......
11
votes
2answers
2k 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? ...
11
votes
5answers
9k views

Validation that also returns error messages

My Create, Update and Delete methods should return a ...
11
votes
3answers
2k views

Can these unit tests be improved?

I'm not the greatest at writing tests yet and I'm starting a new OSS project for learning and as part of it I want to tackle being more effective at writing tests, more specifically quality tests. I ...
11
votes
1answer
501 views

Grid UI layout for a database

I've spent a few days making the transition from WinForms to WPF, and do not have much time for tutorials as the work needs to be done quickly. I was wondering if anyone could take a look at a sample ...
11
votes
2answers
5k views

Math expression parser in C#

EDIT: Added refactored version 2.0 to the end! I have a parser that is supposed to take a string similar to a math expression and return a Tuple of: An array of strings where each string ...
11
votes
1answer
24k views

Converting binary value from BitArray to an int and back in C#

What I am creating is essentially a binary clock face with touch input for setting values as well as displaying - so I need to convert both ways between an int and a binary sequence in a BitArray. I ...
11
votes
2answers
981 views

Parsing Valve Map Files (VMF) into a tree like structure

I've written a small library of objects for parsing of Valve Map Files (VMF). These files are always generated and exported from either the Hammer World Editor, or a Source engine built in map making ...
11
votes
1answer
120 views

400 line method to cycle the movement for players in my game

I use this method to cycle the movement for players in my game. I've been told this method is too large and needs to be cleaned up into smaller pieces, I really can't see much that shouts out "put me ...
11
votes
2answers
200 views

Markdown Markup Editor: MK2

Following on from this question I have added some more functionality to Markdown Markup, and made it more WPF idiomatic. It now supports saving data from any of the four boxes, and loading Markdown ...
11
votes
3answers
1k views

Reusing strings read from I/O

I am working on an application that reads lots of data from the network and puts it in a grid. I noticed that I could save some memory by reusing existing strings instead of always using the new ...
11
votes
1answer
549 views

Multithreading class for asynchronous usage of a custom client/server exchange

I've thrown everything I can at this, and I can't get it to lock or crash. My hope is that I have applied the principles correctly. I write client apps in JavaScript, and this is only the 3rd .NET ...
11
votes
2answers
32k views

Insert multiple rows into a SQL table

I've written the following C# code to insert rows (that a user enters from a web application) into a SQL database. How does this code look? Is there a better, more efficient way to accomplish the ...
11
votes
2answers
24k views

Mapping ExpandoObject to another object type

I am working on a helper method that maps properties from an ExpandoObject to a user supplied object and was wondering if the code could be cleaned up or made any ...
11
votes
2answers
5k views

Using different instances of an object to lock threads

I'd like to use lock objects that are specific to the person I'm updating. In other words, if thread A is updating Person 1, thread B is blocked from also updating Person 1, but thread C is not ...
11
votes
3answers
7k views

Searching a sequence for a pattern

I have written the following tiny extension method to help me when I'm working with sequences in which I have to find a pattern. ...
11
votes
1answer
269 views

Having trouble with KISSing

There's a bit of a weird piece in my API that I'm not too happy about, but I can't seem to see any other way of going about. It involves a IFunctionalityFactory ...
11
votes
1answer
9k views

Generic ASP.NET MVC controller that generates many pages

I recently set out to create an open-source ASP.net MVC web development framework. Specifically, I wanted to automate some of the tasks associated with the creation of data-driven applications. I've ...
11
votes
1answer
14k views

Thread-safe lock-free counter

I was using such code: ...
11
votes
1answer
8k views

Throttle actions by number per period

I want to throttle asynchronous actions at a specific maximum rate of n actions per t period, and have pending actions wait until there is a free slot (rather than drop them). I want to receive the ...
11
votes
1answer
3k views

Injecting SelectList objects into ViewData to enable using EditorFor on dropdown based properties

I have developed a system whereby I use an attribute to state which SelectList to use for an 'FK' property. I would appreciate some feedback mainly on by good ...
11
votes
1answer
4k views

Generic Converter framework

I find myself frequently converting between formats, so I have come up with the following conversion framework. The converter interface surfaces a method to convert from a source type to a target type....
11
votes
1answer
10k views

Implementation of Parallel.ForEach for .NET 3.5

Because the TPL backport not only contains Parallel.* but also PLINQ, concurrent collections, etc, I will try to use this one. Just for fun, I profiled both the TPL implementation and my own, in the ...
11
votes
1answer
2k views

Redis rate limiting in Lua

I've implemented a rate limiter for redis in Lua, and I'm wondering if anyone has any suggestions that might improve the performance. An example use: ...
11
votes
1answer
171 views

Properly destroying the VBE

The disposable wrappers worked exactly as intended... and that turned out being a huge mistake: That's because the .net runtime creates a Runtime Callable Wrapper per-type, not per-instance*; it took ...
11
votes
1answer
282 views

Accessing the Stack Exchange API

Part of a project I'm getting started on requires access to the Stack Exchange API for certain data, as a result I built a .NET implementation to interact with it. The implementation is pretty simple,...
10
votes
5answers
13k views

One-shot events in C#

I have a class that performs some long-running operation. This class exposes a Completed event. I'd like clients that use this class to register to get notified ONLY ONCE when the class completes ...
10
votes
2answers
28k views

Replace each whitespace in a string with “%20”

My implementation: ...
10
votes
8answers
523 views

Cleaning up conditional statements regarding new values

Please suggest ways of cleaning up this code. ...
10
votes
3answers
5k views

TCP Client Class implementation in C#

I tried to implement following class which should handle connecting to a server, as well as sending and receiving data. Your feedback is welcome. Please note I am beginner in .NET and don't give too ...
10
votes
5answers
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 ...
10
votes
4answers
5k views

Find if value exists using SQL True/False Return

Aim: To Assess if one, or more, examples of a value exists in a Database in the quickest time as I only needs a True/False result. The variable is Alphanumeric. Question: Is this the quickest and ...
10
votes
5answers
17k views

Reading from text file with RegexMatch

Below is the method that I have written for reading from a text file. While reading, I need to match a line string to a given regex, and if it matches, I need to add the line string to a collection. ...
10
votes
6answers
2k views

Poker dealer Hold'em

This represents a table (server) for Texas Hold'em. This is not a full Hold'em game but it is working code for what it does. It shuffles, deals the hole cards, deals the board, moves the blinds, and ...
10
votes
2answers
7k views

Simple IRC Bot in C#

This was a simple IRC bot I threw together a long time ago, found recently, and was curious as to if there were any kind of significant improvements that could be made. ...
10
votes
3answers
2k views

Splitting a string into groups of up to 3 numbers, or one letter and up to 3 numbers

There was an interesting idea brought up in The 2nd Monitor where one of our regulars was trying to split a bunch of strings into a specific format. The format should be similar to the following: <...
10
votes
3answers
570 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 ...
10
votes
2answers
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 ...
10
votes
1answer
516 views

Getting the last date where a given week day occurred

I'm trying to learn a little bit about functional programming and as my tool I chose F# since I'm a .NET developer and the environment is more natural to me. In one of my pet projects I'm dealing ...
10
votes
2answers
777 views

Can I stop validating email addresses now please?

Writing code to validate emails is a thing I don't like. It's usually pretty pointless as there's there is actually no right solution, so it leaves me with a certain sense of existential dread. I've ...
10
votes
2answers
280 views

Embedded C# bitpacked arrays to low-level STM32F4 driver for GE G35 RGB LED Christmas tree light

I'm going to be opensourcing some code I'm working on. I don't need help with the code, I just want to make sure my code is readable and my comments make sense. I have a knack for the esoteric. ...
10
votes
2answers
8k views

Generate a LINQ Expression Tree from a filter string

I have a C# Service that takes a filter string and a FilterMap class and generates an Expression<Func<T, bool>> for ...
10
votes
2answers
610 views

Left join query of user profiles

I have the following left join LINQ query that is returning the results that I expect, but it does not "feel" right. I need ALL records from the UserProfile table. ...
10
votes
3answers
163 views

Generating image gauges from a value, min and max

One of the things I was recently investigating was the ability to generate "gauge" charts—that is, a chart which shows where a value stands within a range of values. As an example, if we know ...
10
votes
1answer
168 views

CodeKata: Find all the runs in the set

Given a finite set of unique numbers, find all the runs in the set. Runs are 1 or more consecutive numbers. That is, given {1,59,12,43,4,58,5,13,46,3,6}, the output should be: {1}, {3,4,5,6}, {12,13},...
10
votes
4answers
16k views

Disposing the Context in the Repository pattern

I have a question about the Repository pattern: ...