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
3 votes
1 answer
147 views

Executing method with time limit restrictions

I've created a method which allows to run tasks where results might not be fully computed but still are considered valid. ExecuteFor method can be used if you have ...
FlameHorizon's user avatar
3 votes
1 answer
118 views

Binary heap based priority queue implementation in C#

I made this Priority Queue implementation for C# since it doesn't support updating priorities in logarithmic time complexity. I did some tests and it seems that it's correct. However, I'm not sure ...
Programmer's user avatar
2 votes
1 answer
111 views

2D tile map game: Calculate room tiles a furniture item was placed at

I'm developing for a 2D tile map game. I'm trying to generate a list of tiles a furniture item has been placed at, also supporting multi tile furniture that cover more than one tile. I've written a ...
Josh Hallow's user avatar
  • 1,325
3 votes
1 answer
1k views

How can I make this code more DRY

So I have some POCO classes like this: ...
LonelySemicolon's user avatar
3 votes
0 answers
39 views

Trying to properly modelize app settings in a MAUI app following MVVM architecture

Context: I am working on a relatively simple MAUI app, which includes a Setting page allowing to customize the UX/UI of the app. I am trying to make the best use of the functionalities of MAUI, while ...
Toto's user avatar
  • 131
2 votes
1 answer
127 views

Refactor to get one more layer of abstraction for less repeated code

I might add more methods, but currently I have this design: So connectionString comes from IOptions pattern. Then for each ...
LonelySemicolon's user avatar
-2 votes
1 answer
85 views

C# Implementing a list indexed by generic enums [closed]

I've seen a lot of code bases use Dictionaries with strings as their key. This can be redundant and expensive, so I'm trying to make a class that extends ...
user3337705's user avatar
-3 votes
1 answer
66 views

Best practice code for payment integration [closed]

I am new to coding, and I am doing my best to write efficient and robust code. I am also trying to incorporate design patterns into my code. Could you please take a look at my repository and let me ...
Thomas Charles's user avatar
0 votes
0 answers
39 views

Unity Gesture Recognition Code in C#

I'm new to C# programming and have been working on a Unity project that incorporates gesture recognition using the PDollarGestureRecognizer library and Unity XR Hands package. My application is ...
user17410204's user avatar
2 votes
0 answers
114 views

"Better" enumeration for C#

I've been looking to have "smarter" or "better" enum functionality in C#. There are a few GitHub/NuGet projects out there, but they seem to target newer versions of .NET and I ...
Jesse C. Slicer's user avatar
2 votes
1 answer
93 views

Simple priority task scheduler implementation

My project I am working on requires the following functionality for the processed messages: each message has a priority messages with higher priorities should have precedence over the ones with lower ...
Alexei's user avatar
  • 1,816
2 votes
2 answers
72 views

Form in the Epicor ERP environment

I've written this code for use on a form in the Epicor ERP environment. The code is doing what I need, but since I'm still learning I would imagine that there are better ways of coding. I'm here ...
DaShMa's user avatar
  • 21
1 vote
2 answers
102 views

Compiler grammar and parser are disconnected

In the process of creating my first toy language, I have created the base grammar for it (which can surely be improved upon, feel free to comment). I am emitting C at the moment. \begin{align} ...
Tsaras's user avatar
  • 147
0 votes
0 answers
24 views

Messaging correlation and syncing

We use masstransit and sagas. But I also wanted to correlate some messages without the need for a saga since the syntax for those are pretty verbose if all your need is to sync on a correlation id. ...
Anders's user avatar
  • 670
1 vote
0 answers
82 views

Feedback on a ThrottledInvoker class

State in a Fluxor app can be updated many times per second, with each change triggering a render in Blazor. I wanted to write a class that would throttle these notifications so they don't occur more ...
Peter Morris's user avatar
0 votes
0 answers
35 views

Autocorrelation of a vector series (2)

Related: Autocorrelation of a vector series The given C# source code computes the autocorrelation of a vector series using a Fast Fourier Transform. Can you review this code for correctness? ...
user366312's user avatar
1 vote
1 answer
67 views

Find Method Implementation for Multidimensional Array in C#

I found that Array.Find(T[], Predicate) Method is only support one dimensional array. I am trying to generalize it to multi-dimensional array in this post. The experimental implementation The ...
JimmyHu's user avatar
  • 4,708
2 votes
1 answer
179 views

Autocorrelation of a vector series

Related: Autocorrelation of a vector series (2) The given C# source code computed autocorrelation of a vector series. The listing gives accurate results, but is horribly slow. How can I optimize it to ...
user366312's user avatar
-1 votes
1 answer
55 views

Should the SqlConnection Be a Class Field or Should I Pass It In and Out Of Functions As Needed?

I am writing a C# Database connection class and I am trying to adhere to best practices and produce clean code. In the CreateAndOpenDatabaseConnection function ...
BeeFriedman's user avatar
-1 votes
1 answer
112 views

Should I Break Up My C# Connection Function In Two, To Adhere To The Single Responsibility Principle?

I am writing a C# Database connection class and I am trying to adhere to best practices and produce clean code. In the CreateAndOpenDatabaseConnection function ...
BeeFriedman's user avatar
5 votes
4 answers
271 views

Fizzbuzz in C sharp

I have been asked to implement this and completed that. There was also a request to apply the SOLID principles and use a CLEAN CODE approach. Write a program that prints the numbers from 1 to 100. ...
Mauricio Gracia Gutierrez's user avatar
1 vote
1 answer
52 views

Handling HTTP requests in existing Web Api

I am working in a Web Api project that has the following project structure: Root Controllers Orchestrators Managers Services etc The ...
Yiannr's user avatar
  • 119
0 votes
0 answers
69 views

1d profile cutting optimization

I wanted to make a VBA that creates self-renewing combinations and I actually did it, but Excel was crashing when the combinations increased, unfortunately Excel does not work in multi-item lists. ...
ömür tokman's user avatar
2 votes
1 answer
145 views

Proving that a Window Message is being sent by async/await

I asked a question on Stack Overflow and there's a discussion between @Serg, who posted an answer and @Jimi, whose comments suggest that the answer might be wrong. So I implemented the following code ...
Thomas Weller's user avatar
4 votes
3 answers
1k views

Based on ranges, for a given number, I want to increment it by another number

What is the most efficient way to use a look-up table in C# that works like a range? For a given number, I want to increment it by another number. I have a look-up table like so ...
Bhav's user avatar
  • 143
3 votes
1 answer
147 views

Beginner C# console TicTacToe program

I've been learning to program in C# for a couple months and wanted some feedback regarding a project I completed. Criticism and constructive feedback is what I'm after, so bring it on! I know there ...
Unlived172's user avatar
1 vote
1 answer
101 views

Path Compression Algorithm in C#

Let's consider a simple graph represented by the following edges, where true indicates a visible node and false indicates a non-visible node: ...
Shahar Shokrani's user avatar
1 vote
1 answer
96 views

"stray" point correction in 2D array

I have a code which does the following: For each value v in a 2D array, look at neighboring positions - how far to look is specified by distThreshold. If the count ...
andrewb's user avatar
  • 113
3 votes
2 answers
124 views

Truncating/abbreviating strings in the middle with an ellipsis (…) (or other) separators with a fixed character limit

Problem For some user-facing string, I want to truncate it to some given maximum length (also useful for file name/path lengths on Windows etc.). However, I want to do it a little more elaborately ...
rklec's user avatar
  • 33
0 votes
1 answer
101 views

Store formatting for parts of strings

Suppose we have a string and we want to format different parts of it differently (like in Word). My goal here was to create a data structure that can hold all the various parts of the string as ...
Tsaras's user avatar
  • 147
7 votes
4 answers
1k views

C# console app that draws an image to the console using ASCII

I'm semi-new to programming and want to improve my skills by understanding how people might optimize their code and how the code should be structured since I've been told it needs to do more than just ...
CareeeBugger's user avatar
2 votes
1 answer
56 views

Should I automatically swap matrix dimensions if the passed matrices are formatted incorrectly?

I'm working on making a matrix math object that's as generic as possible. I currently have done multiplication. I've run into a decision I have to make, but first, here's the code. ...
Josh Heaps's user avatar
-2 votes
1 answer
58 views

Is it possible to simplify an event that does the same thing for every panel? [closed]

I wanted to make certain panels have their own custom border color, and the only way to accomplish this (as far as I know) is to manually subscribe every individual panel to a paint event that changes ...
byron's user avatar
  • 59
2 votes
2 answers
205 views

How can I design the configuration of the library with Typed HttpClients in DI better?

I have written a .Net Client wrapper for Google Gemini (Generative AI) REST API and published it as a Nuget package. I am seeking a review of the code. I have spent quite some time in designing how it ...
Junaid's user avatar
  • 137
1 vote
0 answers
52 views

Lockless synchronized access to ConditionalWeakTable

I am inexperienced with writing multithreaded applications, and I am trying to wrap a ConditionalWeakTable (CWT) for use as a generalized container type. I'm aware ...
monkey0506's user avatar
0 votes
2 answers
137 views

EF save method that has three conditions

I created this save method that has two conditions. One condition is checking if coordinatorsId is not 0 and another one is ...
Jefferson's user avatar
  • 359
2 votes
2 answers
103 views

Wrapping SemaphoreSlim.WaitAsync with an IDisposable

The usual way of dealing with a SemaphoreSlim is ...
Ackdari's user avatar
  • 141
2 votes
0 answers
78 views

Implementation of damage calculation based on Final Fantasy 9

I am re-implementing the damage calculations for the game Final Fantasy 9, based on the documentation provided in the GameFaqs Battle Mechanics Guide. Currently, I have two main methods for performing ...
FlameHorizon's user avatar
1 vote
1 answer
79 views

SynchronizedObservableCollection: a thread-safe ObservableCollection

After reading many people talk about the need for a SynchronizedObservableCollection and their implementations I decided to roll my own. I wanted to add a ...
HackSlash's user avatar
  • 382
4 votes
1 answer
120 views

Is there a more performance-friendly way to check and change the colors of a WinForms app?

I'm a somewhat new programmer developing a WinForms application in C# that has the option to change the theme/colors depending on user input. Due to the complexity of the application and the amount of ...
byron's user avatar
  • 59
3 votes
2 answers
198 views

Encrypting large files using RSA and AES-256-CBC-HMAC-SHA384

I developed an application that stores large files. Those files are stored in plain text. Now the project owner wants those files be encrypted on storage, he wants confidentiality, integrity, and ...
Jesús López's user avatar
-1 votes
1 answer
69 views

Queue implementation in C# [closed]

I have tried to implement a queue from scratch, and it doesn't really seem to match what i found on internet, and I am wondering if this is a correct implementation, and what makes using Stack ...
Imane's user avatar
  • 11
1 vote
1 answer
216 views

Concurrent Requests Handling in ASP.NET Web API 2

I was having concurrency issues with my ASP.NET Web API 2 project with .NET Framework 4.6.2. (EF 6), although it has been live on production that has been running for more than 1 year, this problem ...
raysefo's user avatar
  • 197
1 vote
0 answers
60 views

Create a list of objects representing changes between a list of objects [closed]

I'm using .NET 4.7.2. I have this code which should document changes between Person objects: ...
David Klempfner's user avatar
0 votes
3 answers
144 views

Declaring type definition once for all variables

To avoid the use of magic numbers, I created a static class to store some integer values that are represented inside a database. I avoided using enums because I need to cast them every time I use them....
Abcd's user avatar
  • 103
1 vote
3 answers
104 views

Optimisation: Conversion from int to Roman Numeral

A while ago I made a post about optimising the multiplication of every number in an array by 2. With everyone's help I was able to go from 1,500 ns (LINQ) to 30 ns. So I thought I'd try something ...
Henners2002's user avatar
2 votes
1 answer
145 views

Advent of Code 2023 Day 2 in C#

To paraphrase the puzzle, Santa takes a walk with an Elf, and they play a game involving a bag of colorful cubes. In each game, there is an unknown number of each colored cubes in the bag, and the Elf ...
Natecat's user avatar
  • 123
1 vote
2 answers
302 views

Best Practices For A Console Menu App

I am quite fresh to c# and creating programs. I wrote a very basic program which allows you to go through menu selections via up and down arrowkeys and select your selection along with sending you to ...
FloorSign's user avatar
2 votes
1 answer
93 views

Simple .NET Web App for managing family budget

I am creating some small project for my portfolio. It will be an app written in .NET and React but for now I've done backend part and I seek code review. I wanted it to be aligned with DDD principles ...
Gustaw Ohler's user avatar
2 votes
2 answers
49 views

LinearUpscale2DArrayInPlace in Unity Jobs

Well, I have this function which is called in the Unity Job system, I'm profiling it: The code: ...
z3nth10n's user avatar
  • 247

1
2 3 4 5
200