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
0 votes
0 answers
6 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
121 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
0 answers
34 views

Filtering by many fields in ASP.NET Core (C#) [closed]

I'm creating a method of getting data from database and I want to filter it by 2 fields: Code and Value. They can be null (in ...
yaroslove's user avatar
3 votes
1 answer
86 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
0 answers
53 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
91 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
99 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
97 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
  • 137
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
51 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
52 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
181 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
47 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
130 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
  • 361
2 votes
2 answers
75 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
76 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
41 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
111 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
151 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
66 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
115 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
59 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
139 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
101 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
138 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
217 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
86 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
47 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
2 votes
1 answer
71 views

An implementation of encryption cascade

I'm looking for feedback on some source code, I have everything documented and have corrected some errors. Looking to see what I did correctly, incorrectly, and what can be improved. ...
bismofunyuns's user avatar
1 vote
2 answers
200 views

Thread-safe int wrapper in c#

My system is a .NET Core 7 console app, which starts some background threads. I need to pass some int values (counters, etc.) between the main and background ...
lonix's user avatar
  • 143
3 votes
1 answer
63 views

Implementation of aes-cbc-hmac combined with xchacha20-poly1305

I’m using two ciphers in this code that are in this order- encrypt plain text with xchacha20-poly1305 then encrypt the resulting ciphertext with aes-cbc-blake2b hmac. I was told elsewhere rather than ...
bismofunyuns's user avatar
0 votes
0 answers
149 views

can this code be improved in a better way

i am writting a code to get all variants from shopify. as shopify has cursor -based pagination, i want to hit the api until i reach last page. i have write below code. please suggest if i am improve ...
raman's user avatar
  • 171
1 vote
1 answer
109 views

My Drawing Finder

I developed this application for the company I work for. It became increasingly challenging to locate drawings within the myriad of folders, especially when searching for the most up-to-date versions. ...
shiblabi's user avatar
0 votes
0 answers
83 views

C# chess engine performance

I am creating my own bitboard chess engine in C#. I am trying to optimize my make move, unmake move, and move generating functions to get a good fast base. My C# skills are average and got some tips ...
eligolf's user avatar
  • 109
1 vote
0 answers
51 views

Asp.net Core Razor Pages Complex Databinding Select List to Entity List

I'm new to Razor pages. I would like to bind a <select> list to an object's property that is a list of another object (Report.EventyTypes). Consider the ...
yougotiger's user avatar
0 votes
1 answer
192 views

How to optimize the player movement code like in Tomb Of The Musk game?

I've written some code that performs movement similar to the Tomb Of The Musk game. The idea is that the objet should move in a certain direction until it encounters an obstacle. After that, the ...
Hanvil's user avatar
  • 3
3 votes
5 answers
603 views

Optimisation: Fastest way to multiply every number in an array by 2

I'm trying to find the fastest way to multiply every element in an array by a given number, in this case 2. So far I have written a SIMD instruction that performs at 33 ns multiplying every number in ...
Henners2002's user avatar
2 votes
2 answers
131 views

AES-GCM and AES-CBC-HMAC encryption methods

Looking for code reviews of these two encryption methods. And if GCM is better or worse than CBC with HMAC. AES-GCM ...
Bismofunyuns's user avatar
2 votes
2 answers
247 views

Thread safe accessing memory cache using semaphore

I have a Web API and for some requests we are sending requests to a third party API that requires request authentication. It's a simple bearer token, which I'd like to reuse across requests, because ...
Prolog's user avatar
  • 263
1 vote
2 answers
87 views

Refactoring duplicated installation code

I have the following classes: ...
cogumel0's user avatar
  • 181
3 votes
3 answers
203 views

Extracting records from a 2D List of strings

Recently I had an interview question about extracting records that matched certain criteria from a 2D List of strings. The premise was a CSV file was parsed into a ...
Dragonrage's user avatar
3 votes
1 answer
324 views

Recursively load all navigation properties of an entity

I have a table representing a class hierarchy using the TPH model. Some of those sub classes have navigation properties (collections and/or references). I'm trying to preload them as I know I will ...
Irwene's user avatar
  • 195
4 votes
1 answer
349 views

Porting xoroshiro1024** from C to C#, and seeding it

I require a PRNG which: Has repeatable results from a given state. Is both seeded from and has a state containing a sufficiently large amount of data (somewhere in the region of 700 bits or more) to ...
Pikanchion's user avatar
0 votes
1 answer
143 views

Calling the base method from overriden method to add some functionality

I have a small Linked list program which I created for just brushing up the concepts. Following is my Node class ...
Jyothish Bhaskaran's user avatar
0 votes
1 answer
182 views

Why is this not considered better way than Async Await

After so many searches and back-and-forth attempts, I have developed an TCP Server to listen to the network stream and it is working fine. So kindly review the code, and please let me know if this ...
Ravi Kumar's user avatar
5 votes
3 answers
176 views

Generating registration codes

I'm looking for a best practices and security analysis of some code I've written to generate registration codes and avoid duplicates. The class assigns numeric values to the letters A-Z and 0-9 and ...
John Aldrich's user avatar
2 votes
1 answer
281 views

Client disconnection and reconnection in C# NamedPipeServerStream

I have written a C# .NET code that utilizes NamedPipeServerStream to send and receive data. My goal is to ensure that when a client disconnects, the server waits ...
poqdavid's user avatar
  • 131
1 vote
0 answers
113 views

Razor Pages PageModel Initialization When Sharing Data Between OnGet and OnPost

I'm trying to find the best way to initialize some PageModel, avoiding repetition and preventing nullable reference types warnings. Please see the below example. Is ...
user276847's user avatar
1 vote
0 answers
114 views

Wrapping an ExpandoObject within a SafeExpandoObject

I've written code to deserialize a JSON into an ExpandoObject. The only problem with the ExpandoObject is that if you try to access a member which doesn't exist, it ...
rboy's user avatar
  • 111

1
2 3 4 5
201