2022 Developer Survey is open! Take survey.

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
44 views

Sieve of Atkin C#

I don't fully understand how to make the Sieve of Atkin faster than the most ancient sieve. All implementations I found online where slower than the one I made, but still It isn't faster than ...
user avatar
0 votes
1 answer
71 views

Recursively search directories and their subdirectories for images and videos, except system or locked folders

Search directories and their subdirectories for images and videos, except: Windows system folders, locked folders, and folders selected by me. For example, as a developer I have dozens of Visual ...
user avatar
  • 175
1 vote
0 answers
32 views

Multithreaded tcp server accepting two clients with task factory and graceful shutdown

as an exercise from multithreading and networking I have decided to create my own implementation of TCP server accepting connections from two clients (which is I think a pretty common case e.g. chess ...
user avatar
  • 11
0 votes
0 answers
42 views

Generates all pairs (combinations of 2) up to a limit (exclusive)

Any improvements on this combination generator. Seen a lot of combination generators online, but none like this. Found pseudocode at: https://www.baeldung.com/cs/generate-k-combinations Fastest I ...
user avatar
1 vote
0 answers
20 views

Creating a generic base class for singletons in Unity

Singletons can be very tricky to work with in Unity, especially when you dont want to give up on Monobehaviour features. Most examples I've seen make use of ...
user avatar
  • 183
2 votes
3 answers
524 views

Returning the other value of boolean enum

I have a class with a "mode" state. There are currently two modes and we are not likely to add more in the future. The class has a CurrentMode property, ...
user avatar
  • 183
1 vote
0 answers
61 views

Implementation of Concurrent List in .NET

I would appreciate review of this implementation of the concurrent list that is, to my knowledge, currently missing in .NET Core. Requirements Thread safe Lock free Ordered Supports get and set by ...
user avatar
  • 111
2 votes
1 answer
52 views

Managing websocket subscriptions

The following code is pulling data off an exchange. It keeps the subscriptions to the channels because when the websocket client reconnects, all subscriptions are gone and we basically need to ...
user avatar
  • 423
-1 votes
0 answers
31 views

How to random the questions for my quiz game in C# Console App [closed]

I create a quiz game app. The user will answer 3 subjects and it is a multiple choices. After the user answers 10 questions per subject, it will display the score per subject and also the overall ...
user avatar
0 votes
0 answers
37 views

Filter by all properties in an IEnumerable<object> using LINQ [closed]

I've made this code to be able to filter an IEnumerable for every object property but I want to know if there is any way to improve this code. ...
user avatar
0 votes
0 answers
25 views

Using buttons as common for child forms c#

I have mini ERP project in C# winform. So I have too many forms in the project. I have buttons and I want want to use these buttons as common for all forms. I implement codes below but i am not sure ...
user avatar
  • 133
1 vote
1 answer
97 views

Split large strings into parts by last index of character and by max length

This is my method to split strings into parts by last index of character and by max length, the rationale for this method is because I have to send, in a payload via ...
user avatar
  • 135
-1 votes
0 answers
39 views

Use httpClient in class library with console application [closed]

I have one console application and class library in .net core 6 project. I want to call external API in class library. For this, I have written following code in ...
user avatar
2 votes
1 answer
145 views

Split string by last occurence of character within a range

So I would like to split a string in two by the last space within the first 40 characters, the best solution I could think of: ...
user avatar
  • 135
0 votes
0 answers
33 views

Calculate maximum value of expression for potential associations

I have an algorithm that calculates the maximum value of an expression that is made from numbers and * or + by adding parentheses. It has 3 nested loops, so the time complexity should be N^3 ...
user avatar
  • 1
0 votes
0 answers
26 views

Resolver Factory Pattern for IoC in an Asp.Net 6 Web Server

I'm currently testing an experimental IoC pattern enabled by a factory implementation, currently implemented for use in an Asp.Net 6 web server. The pattern is intended to support lazy resolution of ...
user avatar
  • 1
3 votes
1 answer
68 views

Console Slot Machine written in C#

This is my console simulation of the Slot Machine in C#. Please take a look at this code and point out possible ways of improvement. ...
user avatar
  • 39
0 votes
0 answers
101 views

Properly implement MVVM pattern in multiwindow WPF app

I'm trying to develop a SQLite based WPF app (c#) utilizing the MVVM pattern. I'm building this on a decade old laptop with only 2 GB RAM, 20 GB of free storage in it and Windows7. So I'm using .Net 4....
user avatar
5 votes
4 answers
892 views

Naming a method that gets the next enum value or starts from the beginning if the given value is the last

I'm struggling to find a proper name for a specific method (in code named NameOfExtension), and would also like some feedback about its implementation. I am ...
user avatar
  • 153
1 vote
0 answers
44 views

Specification pattern vs Always valid domain model [closed]

Let's say we have two aggregates: ...
user avatar
-1 votes
0 answers
43 views

Re-designing the response type of a method. Instead of throwing exceptions, put these exceptions in an Error property

I'm trying to improve SendAsync because of how ugly it looks, for ex. look at EnsureAuthenticated. I don't like the fact that it throws exceptions when it fails to ...
user avatar
  • 423
3 votes
3 answers
100 views

Json Array to ND Json converter

Problem We have a tool which produces output as json array We have another tool which anticipates input as ndjson (newline delimited json) I need to write a converter to transform json array to ...
user avatar
  • 5,535
1 vote
1 answer
117 views

General web socket client with auto reconnect capabilities

This is a web socket client wrapper with auto reconnect capabilities. First of all, I know I should avoid working with strings to reduce allocation, that's on test purpose. So, ignore the fact that it ...
user avatar
  • 423
1 vote
1 answer
85 views

C# Language Lexer

Here is a Lexer for a programming language I am working on. Any feedback would be appreciated. I only started learning C# a couple of days ago, so please excuse my newbie code :) ...
user avatar
-1 votes
1 answer
51 views

ReadOnlySpan variant? [closed]

...
user avatar
  • 101
1 vote
3 answers
123 views

Executing Method Call - C#

I'm just wondering if there is a better way of executing multiple methods depending on a value? I have a Property that gets the NumberOflegs. NumberOfLegs can have a value between 1-6. If the value is ...
user avatar
1 vote
3 answers
71 views

Saving Multiple Lists to Database - C# Forms

I am trying to store multiple lists to a database but I'm struggling on finding a better way of doing it, as the way I am doing it now, seems to be incorrect. On my form, I have 6 different legs. Each ...
user avatar
0 votes
0 answers
33 views

Abstract instance creation for handler

My application uses several data sources. One is a web-service, the other uses a database context, and in some cases even files on servers have to be retrieved. I am trying to find a way to ...
user avatar
2 votes
2 answers
67 views

ASP.NET Web API for currency

On the basis of the daily exchange rate data of the CB (https://ww.cbr-xml-daily.ru/daily_json.js) it is necessary to create a Web-service using ASP.Net Core, which implements 2 API methods: ...
user avatar
1 vote
0 answers
72 views

What’s the correct usage of volatile keyword in this Concurrent dictionary implementation?

Can I get some guidance around the usage of volatile keyword and design of the existing concurrent dictionary implementation, please. Here are a few design ...
user avatar
1 vote
1 answer
60 views

Get files from disk filtering by size

does anyone knows how I can simplify this code? The objective is to get multiple files from the explorer and validate the number of files, the weight of each file and the total weight. ...
user avatar
0 votes
0 answers
37 views

Structure of a blog-application in ASP.NET MVC

I'm trying to make a small blog-application in .NET 6 MVC (+ EF), but I'm a bit stuck on designing the overall-architecture of the application. Especially when ViewModels are involved. This is (a part ...
user avatar
  • 1
2 votes
1 answer
44 views

Json.Net set the value of the Json object by mixed Json path

Code from: https://stackoverflow.com/a/65715088/6859121 It is use a mixed Json path to set Json value. Even if the object on the path does not exist. This code seems to have room for improvement. Is ...
user avatar
0 votes
0 answers
30 views

Is it okay to remove events from subscription when there is no events

I wrote an application that when you press the start button it prints file paths to list view through events. When I press the start button it subscribes the Engine...
user avatar
  • 237
0 votes
0 answers
47 views

Checking if the string has any characters present in a list of chars

I have this requirement to find if the input string has any restricted characters. The restricted characters are stored in a HashSet. There are totally 1351 restricted characters are present in the ...
user avatar
1 vote
1 answer
34 views

Configure lazy and non lazy DI for automapper

I have the following code to register the dependency injection for automapper: ...
user avatar
  • 631
0 votes
2 answers
106 views

LeetCode: C# fibonacci number iterative solution

https://leetcode.com/problems/fibonacci-number/ The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones,...
user avatar
  • 5,249
2 votes
2 answers
93 views

Optimizing a recursive path finding algorithm

On input i get width and height of matrix, string of text and another string of finalText I want to reach. The characters of the first string are assigned to matrix. My goal is to find shortest way to ...
user avatar
  • 21
2 votes
2 answers
49 views

Comparing the keys in multiple JSON files used for translations in an Angular application

I maintain a number of projects, and several of them feature Angular front-ends. These projects need to be available in multiple languages, at the very least French and Dutch and preferably also in ...
user avatar
  • 10.6k
0 votes
0 answers
34 views

Download Results from API and compare with local database

I'm trying to improve this function I just wrote to be more efficient and readable. It's supposed to Download the results from the API. The results can be from 1-300ish and the API sends back all the ...
user avatar
  • 149
2 votes
1 answer
101 views

Implementation of an algorithm to calculate a check digit for a five-digit number

I'm a newbie in programming, just started about 6 months ago and just finding my way around in C# (clean) code. This is the toy task we have received from our teacher. This is what it should do: New ...
user avatar
  • 23
1 vote
1 answer
67 views

SemaphoreSlim throttling

I am trying to throttle SemaphoreSlim (i.e. allow initialization with a negative initialCount). A scenario could be that you're hitting an API and may notice degradation due to a server overload, so ...
user avatar
1 vote
3 answers
142 views

Best way to get an arbitrary property for a C# class?

I have close to a hundred classes where I need to get arbitrary properties from them at runtime. The calling class knows which properties it wants at run time, but not at compile time. Looking for ...
user avatar
  • 176
1 vote
1 answer
134 views

C# lock on string value

Our codebase is full of locks such as: lock("Something." + var) { .... } This causes issues due to strings not meant to be used in locks in this way. ...
user avatar
1 vote
1 answer
54 views

Tiny Validity class

Here is a part of my new code replacing the old and deprecated old-school one. Let's get to business right away: I document everything with Documentation comments, which are proving very useful so ...
user avatar
3 votes
3 answers
188 views

A refactored payment service, handling several payment schemes

I was asked to refactor a class, to make it adhere to SOLID principles, with testability and readability. I thought I had done a decent job, only my feedback was: a) Unnecessary introduction of ...
user avatar
  • 140
0 votes
1 answer
47 views

Distribute items over array in order to minimize the difference between min and max array values

I came across this problem in a programming challenge a few days ago. I came up with the implementation below, however it resulted in a "time limit exceeded" failure for a few of the test ...
user avatar
2 votes
1 answer
53 views

c# SqlDataReader

This logic get data from a database and checks if the inbound ipAddress is within the range or if its equal to one we have stored in the system. In production its ...
user avatar
  • 521
0 votes
1 answer
80 views

Reading and modify big set of data

I have a method that iterate over my table question in database and then will split a column commentaires and finnally put ...
user avatar
  • 143
3 votes
1 answer
210 views

Convert a c# decimal to big-endian byte array

Following the avro schema documentation for decimals I've created a method to turn a decimal into a byte array. The goals are: Should be represented by a non-scaled integer Should be big-endian I've ...
user avatar
  • 155

1
2 3 4 5
198