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
4
votes
2answers
792 views

Tic-Tac-Toe code using c#

I am a beginner coder and was wondering how to improve my c# console code. It makes a tic-tac-toe game. ...
1
vote
0answers
88 views

A Generic Two Dimensional Data Plane with Common Math Calculation Build-in Methods in C#

This is a follow-up question for A Generic Two Dimensional Data Plane with SubPlane Method in C#. Thanks to aepot's answer. I am trying to implement a series methods to enhance the ability and ...
-1
votes
0answers
26 views

Asp.net Rest Api higher requests

I would like to build a Asp.net (with net5) rest api service, and i would like to know if i'm on right way. This service will cache values from other service Y for X minutes, if client will ask data ...
2
votes
2answers
119 views

Dependency Inversion Principle with connection to a SQL Server

First, this is my first post on this stack exchange site. So please be patient with me. If there is something wrong or you miss something, please let me know. I will add it asap. I am currently ...
-1
votes
0answers
16 views

C# Winforms App ,EF6, DB First with Auto Mapper Generic Repository and UOW context is not updated automatically when database is changed externally [closed]

I've started to work on a single user c# winforms application, with EF6 db first approach, AutoMapper, Generic Repository and UnitOfWork. They have been previously implemented by others former ...
0
votes
0answers
61 views

Grade Book project

I started to learn C# recently by following the official Microsoft docs. I originally created the GradeBook project from Pluralsight which I am now adding my own features to. This section lets the ...
1
vote
0answers
35 views

Is repository pattern violated while using IQueryable outside of it?

I am writting an API backend application using .NET Core and Visual Studio. Here is the solution structure: [ProjectName] - Solution ...
-4
votes
0answers
9 views

Add git sub-module in a repo using LibGit2sharp [closed]

I'm working with a local Git repository in some .NET code using the open source library used by the Visual Studio Tools for Git, LibGit2Sharp. I need to create some submodules. The code I used was: <...
12
votes
2answers
8k views

2D Collision Detection

I wrote this a while ago but wanted to see if I went about it the right way and if my brain is working correctly. I was thinking about these two projects the other day and I recently released the ...
0
votes
0answers
54 views

Is there a way to optimize this graphics/bitmap drawing code in C#?

I am not doing anything fancy so not sure if there are any tricks to make it faster. It's a progress bar where I draw some numeric text on top. I only draw 1 pixel height image and then resize it. But ...
2
votes
0answers
67 views

Split a list of points into a list of lines in C#

I have a list of points (System.Drawing.Point) obtained from an edge finder function that scanned a bitmap for objects. Each point is guaranteed to be a part of an ...
0
votes
1answer
67 views

C# code for Dhond't voting method UK Parliament

Please can you check if the code I have written follows 4 rules of OOP well enough, if there is anything that could be improved or is just wrong I am happy to change (very new to C# sorry if it's ...
2
votes
2answers
304 views

Optimizing odds calculator

I am trying to setup an odds calculator for a best of 7 series, given independent odds for each event. The following code works, but I would like to add recursion to simplify the end. ...
-3
votes
0answers
18 views

Parsing DateTime with timezone [closed]

I am facing difficulty in parsing a DateTime with the structure of time zone: I am trying to parse it this way: ...
2
votes
1answer
342 views

Deserialise Json and Read Stream twice in C#

So this is a modern implementation of a HTTP client, trying to find a way to optimise/simplify this. Specifically the DeserializeAsync method with the GetStream and the compiler statement for if/debug ...
2
votes
3answers
241 views

ArrayDowncasters Implementation for Downcasting from System.Array to Array of Specific Type in C#

I am working with System.Array and I am trying to convert System.Array objects to array of specific type (such as ...
1
vote
2answers
439 views

Refactoring based on OPEN CLOSE PRINCIPLE- C#

I have some code to write Error Logs to different places like Console/SignalR Messages/Text File. The code is as follows:- <...
-1
votes
0answers
52 views

How to use Dependency Injection properly in asp.net core?

I have a legacy Asp.net Core 3.1 application which uses Kestrel server and all our GET and <...
1
vote
1answer
46 views

C# asynchronous tasks training (turn-based simulation)

I know embarassingly little about asynchronous programming in C#, so decided to start catching up. It would help me a lot if anyone checked this basic example I've created. Assumption: we're creating ...
0
votes
1answer
58 views

Methods improvements

I just recently learned how to write Methods in C#. Here is one experiment I made. It calculates addition, subtraction, division, multiplication, and the square root of a number. fill free to give me ...
6
votes
2answers
664 views

C# - Linq - Techniques for avoiding repeating same pieces of code

I am writing a piece of code for C# Web Api, letting the clients to pass a column name and sort direction as parameter. Although there are, like, 30-ish properties, so the following code (despite it ...
1
vote
1answer
108 views

Eliminating repetitions of subsequent items in a list

I would like to convert a list A A = {1, 12, 3, 3, 3, 8, 5, 5 } into list B ...
3
votes
0answers
315 views

OpenCv webcam streaming class for WPF

My goal is to make a class that wraps the complexity of OpenCvSharp implementation to show a webcam streaming into a WPF Image. ...
1
vote
1answer
2k views

Caching XmlSerializer in AppDomain

To work around the XmlSerializer memory leak thing I created this: ...
0
votes
0answers
79 views

Is the right usecase implemenation of ValueTask and Task in C#

I am trying to understand the right usage of Task vs ValueTask in .NetCore2.0(+) or C# 7.0(+) Task - Is a class/object types & uses heap memory should be used in async method when the operation ...
4
votes
1answer
157 views

Configuring NavigationService and NavigationView in one place

Context The main goal located a configuration NavigationService and NavigationView in one place. In order to minimalization a ...
2
votes
0answers
122 views

Tic Tac Toe game using WPF+MVVM

I am looking for some advice on how to create a new ViewModel within an already existing ViewModel. I am creating a Tic Tac Toe game, to improve my knowledge of the MVVM pattern, WPF and C#. I am ...
0
votes
1answer
103 views

Is this correct way to setup DB Infrastructure with repository pattern and Dapper

So, I am using Repository pattern with Dapper and ADO.NET. I have my based DB infrastructure setup as follows: ...
2
votes
1answer
60 views

Generate a bar chart of weekly data from SQLite.NET

I am using Xamarin.Forms, Microcharts and SQLite.NET to create a mobile app. The SQLite.NET database stores details about books (book ID and entry date - the date it was entered in the system). The ...
1
vote
1answer
293 views

Appropriate separation of concerns for this case?

This is a method that calls a web service, it uploads an audio file and fetches metadata back. While the advantage is that there is only one method to call there are a few concerns about it : There ...
2
votes
2answers
157 views

Getting metadata from MusicBrainz service

I've written a program which does the following things: calls third-party utility to get mp3 file fingerprint asks MusicBrainz IDs from AcoustID service asks metadata from MusicBrainz for each ID I'...
2
votes
0answers
76 views

Read compressed XML file inside ZIP and parse data as fast as possible

I am trying to read and parse an XML file inside of a ZIP archive as fast as possible. The XML file is roughly 85GB in size, so I know for a fact that I/O also plays a role here, as I need to ...
2
votes
1answer
65 views

Making DataTable results more readable

I have the method below, which generates backtesting results. However, it's highly unreadable. What could you possibly suggest to me in order to make it more readable? ...
9
votes
4answers
22k views

Threadsafe DBContext in singleton

I found out the hardway that access to DbContext in .NET is not threadsafe. I have a singleton for logging things using a dbcontext. The original version uses something like ...
3
votes
0answers
2k views

Hosted service for queuing and running tasks in parallel in ASP.NET Core

I am attempting to construct a background service for an IIS-hosted ASP.NET Core project that basically queues tasks and runs them, and I decided to go with the ...
2
votes
2answers
1k views

Filter out string sections

I have a helper method to clean up a string and remove pieces that I will be generating again. (defined by the "SpecialKey" Constants) but I've never been real happy with the code. Although I find it ...
4
votes
5answers
219 views

Consecutive whitespace reduction

I pursued an according algorithm with an absolute best performance, the following class embodies the solution. Any comment is welcome. ...
1
vote
1answer
85 views

ConvertAll Methods Implementation for Jagged Arrays in C#

This is a follow-up question for ConvertAll Methods Implementation for Multidimensional Array in C# and ConvertAll Methods Implementation for Multidimensional Array in C# - follow-up. Besides the ...
-1
votes
1answer
59 views

Adding a new class property == new API version?

I have the following code: ...
5
votes
4answers
329 views

Is this a good implementation of a simple “Size” value type

I have created the value type below to represent the desired size for an image. The Size.Default is used in situations where the image is required in the size it ...
1
vote
2answers
60 views

Store, retrieve and delete settings in C# Registry

My code writes, reads, and removes program settings in the registry. I'm using Visual Studio 2019 and my target Framework is .NET Framework 4.8. I'm looking for more elegant functions. Is there error ...
0
votes
0answers
34 views

Resetable async Observable subscription that won't naturally dispose itself

I wanted to have a code review on the following Observable implementation, because there are many opinions and this one might not be the most efficient one. I would like to hear yours thoughts. What I ...
1
vote
1answer
66 views

ConvertAll Methods Implementation for Multidimensional Array in C# - follow-up

This is a follow-up question for ConvertAll Methods Implementation for Multidimensional Array in C#. Thanks to aepot's answer and Olivier's answer. In order to match the usage of the build-in API <...
1
vote
0answers
292 views

Binance.Net getting historical data from start date to end date loop optimization

I'm using Binance.Net and I wanted to get historical candle data from start date to end date which is useful for backtesting. They don't really provide that functionality, so I have to do it myself. ...
2
votes
1answer
64 views

Reducing Inventory Quantity When Order Is Being Processed

I've got a method which removes quantity from inventory when an order is completed. If there is not enough inventory quantity available, the order completion fails and the sql transaction is rolled ...
2
votes
1answer
62 views

Multiple producer single consumer on the same thread

I implemented a multi-producer single consumer class, with an important restriction that once the consumer started working, it must continue its work on the same thread (the reasoning behind this is ...
4
votes
2answers
149 views

similar code in several methods

I have method which checks period and return schedules: ...
0
votes
1answer
83 views

Big Sorting - Performant Sorting

Consider an array of numeric strings where each string is a positive whole number. Sort the array's string elements in ascending order of their numeric values, and return the sorted array. Return: ...
-2
votes
1answer
63 views

Testing Code That Has Time Delays [closed]

Whilst refactoring an app I'm working on I moved a piece of code from the business logic layer to a helper. The code in question is a fire and forget method that will execute a piece of code if it ...
2
votes
1answer
54 views

This code loops through a GlobalEmployeesList, eliminates duplicate email and phone records for the selected employee, and populates listboxes

I have a DataGridView which displays an employee list. I use the employee ID to filter my global employee list and display information about the selected employee in various listboxes. This is my ...

1
2 3 4 5
189