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
1 vote
1 answer
34 views

Asp.Net Core CacheKey Management

I created cache management structure for Asp.Net Core and Redis. But i dont know is this best practices or bad. My Github Repo First one is Store my entity keys class is ...
user avatar
-2 votes
1 answer
40 views

Small units: property initialization [closed]

We're using Sigrid as our code analysis tool and one of the metrics it uses to measure code maintainability is the well-known "unit size". Units between 1-15 lines of code is deemed to add &...
user avatar
0 votes
0 answers
18 views

Export dataGridView to an Excel Worksheet in c#

I have a dataGridView in a WindowsForms. I also have a button to export this dataGridView to an Excel Worksheet. If the button will be clicked, the data in the dataGridView will be exported to a XLSX-...
user avatar
  • 115
3 votes
2 answers
68 views

Parse the weekly menus of a German delivery service

I am a C# beginner, and I wrote a program that parses the weekly menu of a German delivery service. It works fine and I think the code quality is okay. Can anyone with more experience than me review ...
user avatar
-1 votes
0 answers
25 views

What's the proper way of handling an error when iterating though objects [closed]

So I'm currently trying to learn how to use interfaces and I decided that I would make an app which simulates making a restful request to Google and YouTube and it would get the total amount of search ...
user avatar
  • 119
0 votes
0 answers
47 views

ASP.NET Core 6 background DB logger

In an application, many actions need to be logged in the database. but this logging process should not slow down the request. So they should be done in an asynchronous queue or something. This is my ...
user avatar
3 votes
1 answer
67 views

"Select followed by First" versus "First followed by Select" when summing the data for a student

I am wondering which one I should choose between the following two options when I need to calculate the sum of Data of the student with ...
user avatar
0 votes
2 answers
97 views

Is this a good way to check for an anagram if sorting is not allowed?

So I decided to lookup some algorithms, and one of the ones I found was.. "Check if the string is an anagram" and without using Google for more than checking what an anagram is, I decided to ...
user avatar
  • 119
0 votes
1 answer
50 views

API Data Load method advice- too many parameters per method?

This is my first question so please let me know if this is too vague/broad and I will do more research on question asking. I have implemented a handful of data loaders in C#, and have come to the ...
user avatar
  • 1
2 votes
3 answers
85 views

Deserializing Nested JSON Data with variable rootName to C# Class

I am working with JSON API data in .NET6 and was having trouble de-serializing nested data that has a variable rootname since my class type will never match what's in the JSON string. ...
user avatar
  • 63
1 vote
1 answer
42 views

NTP client displaying reference, originate, receive and transmit timestamps periodically with graceful shutdown in C#

based on this stackoverflow topic: https://stackoverflow.com/a/12150289/15270760 I have decided to create a simple NTP client displaying difference between NTP server response and DateTime.Now called ...
user avatar
  • 45
0 votes
1 answer
72 views

Sorting Dictionary in a lexicographical order and applying MD5 encryption

I'm sorting a Dictionary in a lexicographical order and applying MD5 encryption. I would like to wrap the sorting somewhere inside the encryption method or so. Official Java example - here Docs <...
user avatar
  • 427
1 vote
0 answers
83 views

Simple AES encrypt/decrypt methods for .NET 6 and .NET Framework

I wrote some AES encryption/decryption methods with the following requirements: Inputs should be easy-to-use strings. Something encrypted in a .NET 6 app using these methods should be able to be ...
user avatar
  • 5,572
1 vote
1 answer
76 views

ViewModel for meetings and rentals

I am bringing up to date an old Xamarin app. I am concerned mostly with any design patterns I should be using or anti-patterns I shouldn't be using. This is my first attempt creating a ...
user avatar
  • 487
0 votes
0 answers
95 views

Subscription manager - use cases with same parameters

The idea behind the SubscriptionManager class was not just to keep the subscriptions and resubscribe on reconnect, but also to support multiple callbacks in case of ...
user avatar
  • 427
0 votes
1 answer
52 views

Singleton generic implementation of simple LinkedList

I would like to ask if the implementation is ok, and what I can improve. Although I'm not sure if the Singleton is working properly. ...
user avatar
  • 1
0 votes
0 answers
32 views

Hangfire context constructor injection

I tried following IHttpContextAccessor pattern but for Hangfire context. What I'm mostly interested in is CustomScope class with Resolve method. I'm using ActivatorUtilities there because otherwise I ...
user avatar
  • 101
3 votes
0 answers
122 views

Async FIFO processing of database writes - naive implementation in .Net 6

One of the companies I was recently interviewing with gave me a following task to implement in a day or two using .Net, just to see where my coding abilities are at: Implement a Web API that gets ...
user avatar
  • 31
-1 votes
0 answers
47 views

Under Pressure MemoryCache

Goal is to make MemoryCache evict based on memory pressure. Some concerns is if I should call GC.Collect(0, GCCollectionMode.Forced) As I don't see System.Buffers....
user avatar
  • 4,096
1 vote
2 answers
62 views

Union Polygon Algorithm

This is my attempt at creating a Union Algorithm for an arbitrary set of any number of arbitrary simple polygons. It works for both convex and concave polygons. ...
user avatar
0 votes
1 answer
91 views

Deleting entities asynchronously in C#

I have a method that takes a collection of objects, and in turn calls a method that handles a single object. My question is, do I need to handle the tasks coming from the ...
user avatar
  • 133
2 votes
2 answers
84 views

Wielding .NET masterfully to encode non-alphanumeric characters into utf-8 hex representation

I have these two methods that work, but I also hate because they almost certainly can be improved. I'm hoping to gain some guidance from others who are more knowledgable of .NET's offering for ...
user avatar
  • 23
1 vote
1 answer
56 views

Initializing Class from constructor [closed]

...
user avatar
0 votes
0 answers
93 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
90 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
  • 177
3 votes
2 answers
117 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
  • 45
0 votes
0 answers
67 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
33 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
  • 184
2 votes
3 answers
551 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
  • 184
1 vote
0 answers
103 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
59 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
  • 427
0 votes
0 answers
28 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
102 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
2 votes
1 answer
155 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
35 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
27 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
100 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
109 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
908 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
46 views

Specification pattern vs Always valid domain model [closed]

Let's say we have two aggregates: ...
user avatar
3 votes
3 answers
127 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,750
1 vote
1 answer
152 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
  • 427
1 vote
1 answer
97 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
56 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
84 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
35 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
86 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
78 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
61 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

1
2 3 4 5
199