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
1answer
22 views

Generic Base Repository implementation with Unit of Work in C#

I have seen a lot of Repository pattern implementations with Unit of Work. The simplest way of implementing this I came across is using hard-coded repos (such as this one), while the way recommended ...
0
votes
2answers
37 views

Retrying a RestRequest

I wrote a method that lets me retry RestSharp requests when a specific exception is thrown. Here's the code for that method: ...
1
vote
0answers
23 views

Achieving same abstraction by replacing JObject's implementation with System.Text.Json alternative

I'm trying to improve the following Binance Web Socket API wrapper. I like it because it uses System.Reactive and it takes advantage of the combined web socket ...
-3
votes
0answers
69 views

Is relying on exception handling a good way to ensure that the app's work is done correctly? [closed]

Contextually, I'm evaluating if a member exists with the supplied information. This, ostensibly, is intended to prevent the addition of new members with the same details. The user will be provided ...
-3
votes
0answers
60 views

How to get rid of TryParse in this code? [closed]

I believe that using TryParse is not a great idea here. How to improve this part? ...
0
votes
1answer
39 views

Use an exception to check if item in dictionary

I am using a KeyNotFoundException to check if an item exists in a Dictionary, creating it when the exception is thrown: ...
0
votes
0answers
30 views

ASP.NET Core dependency injection in class library with params

I know this question could be the new variant of other 1million questions but before you say that, let me explain what I'm trying to achieve. I have a lot of APIs and want to create an SDK. There is ...
2
votes
1answer
58 views

A Custom Range Partitioner

Terminology usage: I will use chunk, page, partition, or subrange interchangeably. I frequently use and promote using the System.Collections.Concurrent.Partitioner ...
-2
votes
0answers
21 views

Mysterious ArgumentOutOfRangeException between array and List implementation [closed]

So I built a method containing three for loops which essentially tried to match items in list a) with items in list b). It worked fine, but to try and improve it for reasons which are not (I think) ...
3
votes
1answer
31 views

C# duplicated attributes on Azure Functions with OpenAPI specifications

I'm developing a REST API using Azure Functions with .NET 5 (Isolated) and I want to add an OpenAPI spec for each route. But it looks like this: ...
3
votes
2answers
134 views

TicTacToe Objects calisthenics OOP

I'm learning Objects calisthenics and I was practicing with the typical Tic Tac Toe game, I was wondering if you could gimme feedback about my mistakes (Algorithmic problems, logic, and especially OOP ...
2
votes
2answers
151 views

Sum of 2 arrays using multi threading

I'm trying to implement sum of 2 array using multi threading. I expected that when I use more threads it will be faster than when I use one thread, but that isn't the case. ...
0
votes
0answers
47 views

Best approach to combine repositories logic

Let's suppose I have 2 repositories: first is responsible for creating job and return jobId second is responsible for creating ...
0
votes
1answer
94 views

Custom Binance API wrapper around IHttpClientFactory

I made a custom Binance API wrapper (BinanceRestClient) which uses IHttpClientFactory in order to prevent socket exhaustion, ...
2
votes
2answers
123 views

How can I shorten my tic tac toe game?

At the moment, it is simply massive. I already reduced the size by about a hundred lines but it still seems way too big... Would appreciate some help :) ...
2
votes
1answer
95 views

Using fluent builder pattern for generating pdf

I'm testing to use a fluent builder pattern for generating a pdf file using AbcPDF. I've looked at several methods of accomplishing this and I'd be very glad to get some input on what I've written so ...
1
vote
1answer
96 views

How can I implement this calculator in a better way?

I have this calculator. The user is asked to provide three numbers as well as the numeric operation they wish to perform. Based on this input, a certain case will be executed. The calculator is ...
3
votes
1answer
162 views

Learning Sockets in C# (.Net Framework), Suggested Improvements?

I'm just learning how to allow interconnected apps via Sockets, watched a tutorial last night and based on that this is what I've gotten: Server.cs Code: ...
2
votes
1answer
75 views

Simple stack based interpreter, C# style

I wanted to see how simple it would be to implement a stack-based interpreter in C# based on this question: Simple stack based interpreter The program works with the command line arguments which can ...
0
votes
3answers
770 views

Use less memory and make it runs faster (if it is possible)

I have to improve this code that searches for missing and duplicates values in a list: ...
1
vote
1answer
46 views

JsonResult Building menu

This logic checks different method and adds links to response that is returned to a view. I there a better way to do this ? ...
1
vote
4answers
96 views

Sorting based on multiple fields using IComparer

I use the below code to sort List<DataAccessViewModel> list. Here is the sort order : PriorityScore ...
1
vote
1answer
42 views

Reading inbox from a specific sender and for a specific subject in order to save excel attachments

In my .net core console application, I am reading a mail inbox and saving excel attachments from a specific sender that has a specific subject. It is working as is expected, I wonder if there are any ...
1
vote
2answers
93 views

Getting the total image value

In a previous question that I asked: Get image value total, I learned to use LockBits to speed up my code execution's time. Since then I have changed my code to Ham the distance instead of just ...
1
vote
1answer
117 views

Time-Sensitive Synchronized Transfer of Data Buffer in C# to Multiple Clients

This is a C# program that is a reference implementation, it will be used to make a C version after it is stable and bug free. The programs are supposed to simulate sensor data collection and ...
0
votes
0answers
38 views

Sending emails from .net core console hostedservice

In my .net core hosted service console application, I am reading a database table, retrieving some values, and based on a status, I am sending emails. It is working as it is expected, I wonder if ...
1
vote
3answers
104 views

Verify that 5 Textboxes have some content

I'm new to C#. I have created a form that has 5 text boxes and this function checks to see if every text box has text in the box. If not, then it displays a message box saying "Error (Add Text)...
4
votes
1answer
81 views

Determine whether an array contains duplicate values

My solution for the leet code problem to search an array of ints for duplicate values and return a boolean seems quite efficient (< 90% of submissions runtime). However, I am currently reviewing ...
1
vote
0answers
38 views

Alert system for game or simulator

I am creating an alert system for a game/sim in C# that keeps track of negative actions performed by the user during a training exercise. There are preconfigured alerts that have data, such as UI text ...
1
vote
1answer
67 views

Unittesting in .NET 6 with XUnit

I'm trying to learn and write best practice unittests and practice test driven design. Can you give me some tips and review my code? ...
0
votes
1answer
97 views

Factory pattern to build multiple models

I have used the factory pattern for one of my projects. I want to know if this is a good design or if my code can be improved to make it as fast as possible. I am not an expert in C#. This is what I ...
0
votes
1answer
87 views

How to make this more readable with many if else [closed]

Let me just say this right off the bat: If-Else is often a poor choice. It leads to complicated designs, less readable code, and may be pain inducing to refactor. The objective of this method is to ...
5
votes
0answers
105 views

dotnet - creating db records in bulks in a background job

Use case I have a site that (at peak time) will serve 1000 requests per second. Each request should trigger a record in an SQL Server database table. Requirements The request must not fail, even ...
2
votes
1answer
82 views

Reading excel files and save data into database

In my .net core console application, I am reading multiple excel files and bulk copy data into a database table. It is working as it is expected, I wonder if there are any improvements to make it ...
0
votes
0answers
49 views

Program that retrieves icon name and create sql file

I would like to code review of my program. I would very much like to request a code review. I would like the directory.getfiles statement to retrieve only files with the specified name. Regards ...
1
vote
2answers
67 views

Download and unzip an XML document

I am working on an integration software. I will need to download a list of products and import it into my website. The list of products will be downloaded from ...
7
votes
1answer
332 views

Find all possible ways a rook can move to a diagonally opposite corner without going back to an already visited square

This question seems similar to this one: Find number of unique paths to reach opposite grid corner but is entirely not. For moving from upper-left corner to lower-right corner we are not restricted to ...
1
vote
2answers
144 views

I Made a Simple BattleShip Game On C# Console

I made a simple battleship in C# console with a little AI ( just a little ) and The goal of this practice is improving my knowledge about OOP. Game Rules: 1.You Attack To The Enemy then he Attacked ...
1
vote
1answer
79 views

Parsing data from different file formats

While setting up applications to communicate between various different trade partners and our WMS software I often have to parse very similar information from various different file formats. In this ...
1
vote
2answers
87 views

Moving files according to paths in database

I'm trying to move a large number of files. I get the path of source and destination from database. It takes hours to move images, and I was wondering if there is a faster way for moving large ...
0
votes
1answer
40 views

Entity Framework - component shop using polymorphism and generic repository

I am creating a .NET Framework MVC EF application for PC components. I wanted to make full use of inheritance, polymorphism and generic repository pattern - but was wondering if my initial design ...
4
votes
1answer
445 views

Get image value total

Below is my code: ...
2
votes
2answers
100 views

Serialize nested objects and arrays to querystring

I need to convert objects (potentially nested) and collections (int[], IEnumerables, object[]...
3
votes
2answers
163 views

string increment

Last night I was practicing incrementing strings. What it needs to do is increment the last character if it is a digit or letter. Special characters are ignored. The code that I have written does the ...
5
votes
1answer
98 views

C# Console Snake Game

I was busy writing an answer for this question when I realized that I was busy creating a new solution without explaining what the original poster did wrong, again. So I decided to rather post what I ...
3
votes
2answers
108 views

I made a Simple Score Game in C# Console

I've created a simple score game. The goal is improving my knowledge about OOP. This is my Main method: ...
1
vote
1answer
95 views

Beginner CRUD Console Application

I wrote this basic CRUD app + simple report so I could practice talking to a db directly. I purposefully avoided repository pattern and Entity Framework and only used a library to show the coming data ...
1
vote
1answer
74 views

Find and replace all substrings in a string

Given a list of strings paragraphs and words. Check each paragraphs's item for containing <...
3
votes
1answer
85 views

Simple item and inventory system in C#, my first actually competant looking piece of code as a beginner. Really proud of it

Items.cs, Creates dictionaries, enumerators, and classes for every type of item. ...
0
votes
2answers
153 views

How can I make this faster

Hello I have this method that returns an IEnumerable list , it takes 5 seconds to execute , so I want to know how can I optimize it side performance time of response. ...

1
2 3 4 5
195