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
0answers
19 views

C# Console, Connect 4 Game

this is my second post here, and the second project I made. I wanted to know, how to improve my code of connect-4 made in c# for console. ...
0
votes
0answers
11 views

MultiLingual Project including routing

One of my staff wrote this application in .netCore 3.1 about 18months ago. It works "to a certain extent" but I feel like its bloated and perhaps isn't the best way. I work somewhere were ...
1
vote
0answers
28 views

LeetCode: range sum query mutable c#

https://leetcode.com/problems/range-sum-query-mutable/ I am trying to solve this question using dynamic programming. I guess the guys in leetcode want to limit us to use segment tree or one of the ...
0
votes
0answers
25 views

Linq query to merge overlapping elements

I have this class representing a period of time: ...
0
votes
1answer
48 views

Rethrowing unhandled exceptions later in the catching method

I have a worker class that catches uncaught exceptions and logs them for tracking purposes. However, I do NOT want to swallow those exceptions, nor do I want to abstract them (i.e. losing the stack ...
0
votes
1answer
46 views

c# make synchronization function waitable and cancelable

I need to call some synchronization function and need they running in background and canbe canceled. So I write this: ...
1
vote
1answer
59 views

ForEach Methods Implementation for Multidimensional Array in C#

I am working with System.Array and I found that the input parameter of ForEach method ...
2
votes
1answer
45 views

Remove redundancies in similar properties

I have a lot of redundancy here, but I am not sure how could I make it look shorter. ...
-1
votes
1answer
44 views

Making a Dhond't system in C# by reading from a data file

I wanted to know if i have used abstraction and encapsulation effectively here, and if not where can i improve thank you. (follow up from my unworking previous version) MAIN ...
0
votes
1answer
68 views

Object-oriented Snake game

Right now I have a snake game that is working but I need a way to make my code look better and work better. A method I named GameSense is very long and I need a way ...
2
votes
3answers
67 views

Filter functionality Project using C#

I am simply implementing a filter function for one my forms. I'd like to hear some reviews where I can improve in my code or my functionality :) Summary I have 1 textbox and 2 comboboxes (See image ...
0
votes
1answer
52 views

LeetCode: Sort The Matrix Diagonally C#

https://leetcode.com/problems/sort-the-matrix-diagonally/ A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-...
0
votes
0answers
36 views

.net core console app read from external API and write into a database

I have a .net core console app that gets some data from an external API and inserts it into a SQL database table. It is working as expected but I wonder if you guys have any suggestions to make it ...
0
votes
1answer
39 views

Divide a 3D matrix into multiple smaller 3D matrix

I'm trying to build an extension method that will allow me to subdivide a huge array into much smaller ones. My current code is the following but it still takes about 2s to generate with an array of ...
1
vote
1answer
68 views

A Tiny Image Tagger Implementation in C#

I am trying to implement a tiny image tagger with customized tag options in C#. The main window is as follows. The left block is a picture box MainPictureBox and ...
1
vote
1answer
47 views

Byte array comparison - efficiency

I have a TCP Listener with NetworkStream that reads 530 bytes from the Client once a second. Within the TCP Listener ...
0
votes
0answers
17 views

Azure - Dynamically polling until certain conditions are met - using Azure Durable Functions

Anyone interested in reviewing and sharing comments on the following approach? Requirements: Job - Code that executes and performs certain action JobGroup - One or more Jobs grouped to perform some ...
0
votes
0answers
43 views

Iterating over a C# range

Using GetEnumerator extensions added in C# 9 I was able to do the following: ...
0
votes
0answers
26 views

LC medium, matrix set zeros, accepted answer but not top

I've solved LC medium problem, set zeros. Below code is accepted and all test cases were passing. But my code came in the last 10% of accepted answers wrt performance. Can someone help me identify ...
0
votes
1answer
33 views

optimize integer validation

I have some classes with properties, wich could only have numeric values in a given range (e.g. 0 to 8). This should be validated and wrong values prevented with an exception. The given behavior may ...
1
vote
0answers
43 views

Excel datamapper with fluent config

Example of usage with header: ...
0
votes
2answers
58 views

Import Xml and Csv files into database

I have a simple service class here which import csv or xml file into database using .NET Standard library C#. Do you have any comments? Are there any recommended techniques to use instead of the ...
8
votes
3answers
1k 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. ...
3
votes
2answers
143 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
32 views

Asp.net Rest Api higher requests [closed]

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
1answer
65 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 ...
0
votes
0answers
64 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 ...
0
votes
1answer
106 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
0answers
81 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 ...
2
votes
3answers
245 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
votes
0answers
55 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
52 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 ...
6
votes
2answers
671 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
109 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 ...
0
votes
0answers
81 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 ...
0
votes
1answer
104 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
71 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 ...
2
votes
0answers
135 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 ...
2
votes
2answers
158 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
77 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 ...
1
vote
0answers
101 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 ...
2
votes
1answer
66 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? ...
1
vote
1answer
87 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 ...
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 ...
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 ...
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 ...
1
vote
1answer
67 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 <...
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 ...
-1
votes
1answer
60 views

Adding a new class property == new API version?

I have the following code: ...

1
2 3 4 5
190