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

ForEachAsyncSemaphore asynchronously processing tasks but enable fast fail

I know this has been done many times before, but this is my existing code taken from a sample I found to async process a list of tasks. I've seen Task.Run in use before in many examples, but I'm ...
1
vote
1answer
54 views

Code optimization. How to make the process run faster?

I'm trying to write code that reads data from a CSV and pushes it to a Salesforce application using the API. My code processes the data in a for loop, but it takes a long time (3 hours) to run the ...
0
votes
0answers
38 views

Code of Using AbstractFactory [closed]

I'm working on some project on which need to track final product of specific Animal. There is much more in background, like feeding, vaccines etc... In that project for keeping the code clean and easy ...
1
vote
1answer
36 views

Execute .NET Core 3.1 background worker tasks simultaneously

I have following code: ...
1
vote
1answer
31 views

Updating Multiple Collections In ViewModel Based On A Single ListView Selection - WPF

-I have a ListView, and its SelectedItem property is bound to EmployeeModel SelectedEmployee in my VM, and it implements the Set method from MVVM Light. (Basically, ...
1
vote
0answers
48 views

Filtering what strategy to use in strategy pattern [closed]

I have a situation where I've used the strategy pattern but got many different strategies that are available to the client code that needs to select the appropriate strategy, this is because there's a ...
1
vote
1answer
38 views

Asp.net core response caching with custom key values

I'm trying to build a response cache with custom key values (from headers and cookies). Here's the code I have so far, and it kinda works, but I need a second opinion or suggestions for improvements. ...
-2
votes
0answers
34 views

A simple Dll injector using c# console [closed]

hey guys apolgies for this. completely new to coding and me and another guy have decided to make a menu for a game. i have made this so far ...
6
votes
1answer
209 views

Rock, Paper, Scissors - Applying OOP Principles

I would be grateful for a code review of my first "real" C# project (https://github.com/michaeljsiena/RockPaperScissors). It's a basic rock, paper, scissors console game. It's probably quite ...
1
vote
1answer
61 views

How can I optimise a foreach calling an API? The code calls an API and returns the first string reponse

I have the following code that makes a call to an external API, processes the response and returns a string. The problem is it is taking a very long time to process. I can't do anything to the API, ...
0
votes
1answer
38 views

Use Request with Fileupload in Controller

I wrote a fileupload function for my application. Basically the application is a web based folder structure, which has files included. I don't know, but I am not happy with it. Is it too long? Can I ...
0
votes
0answers
50 views

C# How to speed up datatable updation for high volume of data

Reading data from xml file and load data into datatable. i can not load data into List because datatable has some dynamic column whose name is not known. I have one List and one datatable. ...
1
vote
0answers
60 views

How to make this algorithm faster. Calculates and searches through large arrays

Ive got this algoritm thats "complex". The comments in code give examples of how large the various data types could be. My cpu usage is less than 10% when running this and ram usage is good. ...
1
vote
3answers
56 views

How to refactor a method with many prameters that sets a bit array

I've written a method that is going to set a bit array by passing bool parameters to be able send correct command ...
0
votes
1answer
109 views

Is it possible to refactor these two similar methods that handle T and List<T>?

Is there a way to unify or refactor two methods that do basically the same but the difference being of handling a type of object or a collection of the same type of object? The following is an ...
2
votes
1answer
47 views

The multithreading model to clean ConcurrentQueue in C#

I have some code that populate EventfulConcurrentQueue which is ConcurrentQueue. So I need to save all data from ...
1
vote
2answers
89 views

I want reduce the time complexity for this ladder problem to find the minimum ladders required

I was trying to attempt below given challenge. I tried multiple ways to solve the problem but none of them were good enough to pass the time limit. Please advise if you have any idea to improve on ...
3
votes
3answers
82 views
1
vote
2answers
69 views

Todo application implementation

I am new to c# and decided to write a classic todo app. The implementation of my application now is like this: there is a Task class that describes the task. The List class acts simultaneously as a ...
0
votes
2answers
70 views

How to replace the given email address with a value in a given input?

I have written the below method to replace some of the email domains like @gmail.com and @yahoo.com with a given text. ...
1
vote
1answer
51 views

.Net 5.0 Get User Email From Claims

From searching online I have identified two ways to get the user email, but I don't know if either has pro's/con's beyond Option.1 being a larger number of lines of code? Option.1 I have a dedicated <...
2
votes
2answers
72 views

Dapper with shops and payers

I live in the buildings that have 50 people in it and for each floor splits into 2 groups each group is from ~9 people. I'm trying to build an Xamarin app (IOS, ANDROID ,Win10,maybe web app) to make ...
0
votes
1answer
88 views

Improvement for generating excel with many data

I have the problem, my methods become slower and slower after many data. My methods can generate 100 rows with 20 columns around 1-3s, but after that my methods become slower and slower. And for ...
0
votes
1answer
55 views

Merging every two objects into single single object making group by a property C# LINQ [closed]

I have a object list like below. I want to join every two rows into single row based on column B. It is sure that only two rows would be there for every single column B value. Input Output However, ...
3
votes
0answers
71 views

C# class library for managing recurring background operations

I have written a class library for creating timer-based bacground operations in .NET projects. The idea is to be able to create and manage (start/stop/resume/cancel) recurring background operations ...
2
votes
1answer
67 views

Is this a good design for runtime Macro execution?

I am developing a system for runtime macro executions in an automatic test environment. Macros are defined in an xml and are for configuring multiple devices/DUTs for a specific use case. The xml ...
2
votes
2answers
133 views

Recursive function for bubble sort

I often see nested loops as a solution to the bubble sort, but my solution involves a recursive function. Is the following solution less efficient than the traditional method? ...
1
vote
1answer
84 views

A simple encryption scheme 2.0

This is a follow up to my previous post. I've used a BCrypt library to create a key from the passed in password. I then separated out the salt from the hash. The encryption is done using the salt ...
3
votes
0answers
99 views

C# Procedural Mesh Generation Optimization

I'm making a terrain-deformation system in Unity that utilizes the common marching-cubes algorithm. So far I've gotten the system working, employed Unity's job system and burst compiler, and managed ...
-1
votes
1answer
37 views

Better way to keep a list of items from a Http Request?

I have a simple web api where each request "item" is stored in a list and thus a list is built without creating a new list per request. I have achieved this via dependency injection , but I ...
2
votes
1answer
64 views

Asp.Net overall design pattern integrating REST, dependency injection, and Hosted Services (See full project at Github)

I'm new to C#, and want to conform as much as possible to good design patterns. This code is the beginning of a Microservice, running as Asp.Net. It is based on a Microsoft tutorial doing similar work....
4
votes
3answers
213 views

This code is a non-static C# class for rolling a number of dice

Hello Everyone! Fellow human beings, today I present to you my dice rolling script! Behold, in my amateurish attempt at some raw C# code. Perhaps this will remain here regardless of the dozens of ...
4
votes
0answers
32 views

SmartUnit: Unit Testing with DI

I was thinking about how unit tests require you to manually instantiate all your dependencies, even though many of them are the same for every test or don't really matter (such as logging, where ...
3
votes
2answers
76 views

How to iterate through data and write to excel file quicker with C# and openXML

I have a pretty simple method that grabs data from an sql query and then puts it inside of a list and finally iterates through two for each loops onto an excel file. It works fine with small amounts ...
-2
votes
1answer
92 views

Can I refactor my code anymore? [closed]

I have written one method; however I feel I can refactor it even more but not sure what Can someone help me here? ...
1
vote
1answer
47 views

UDP image livestream from Android device to C# desktop application

After searching a lot, on how to do it and not finding any good solutions, I implemented my own UDP livestream from an Android device to a C#/WPF desktop application. It works, however, since I get ...
0
votes
1answer
84 views

Retrieve filename and ID with Google Drive API in C#

I am trying to retrieve filename and ID list with Google Drive API (the latest Drive API version v3 is used here) as a first step in order to analyze and manipulate these files on Google Drive. The ...
3
votes
0answers
51 views

Calling multiple clients from API controller methods?

Hi I have a requirement where in I have to call two different client methods from same api in .NET Core and I have structured my code as follows. THis is working fine but Please give me your ...
1
vote
0answers
37 views

Record status of http call to show in the UI

What I am wanting to do, is record the status of a HTTP call, so that I can give the user some feedback in the UI, rather than either succeeding silently, or showing a grim error. What I have done is ...
0
votes
2answers
114 views

Generating unique names for things like filenames

There are systems that when you duplicate an asset, the new assets are created with an index, so that the name do not collide. For instance, if I have an asset called ...
1
vote
1answer
57 views

Index IValueConverter Optimisation

I've created an IValueConverter in order to Bind to the index value of a Collection. However it seems to be rather slow/infefficient and I wonder if there is a ...
1
vote
0answers
65 views

DataGridView Undo/Redo Manager in C#

While answering this code review question, I proposed a solution with List<DataTable>. I am trying to encapsulate this data structure into a "...
3
votes
3answers
98 views

Throttled execution of an enumeration of Tasks

Example of use: var users = await usernames.SelectTaskResults(GetUserDetails, 4); where GetUserDetails(string username) is a ...
1
vote
1answer
81 views

Create a cancelable Task background runner class

My requirements are: Create a .net 5 class that encapsulates a task runner (i.e. a wrapper around a Task object) The class should be thread-save Consumer of the class should be able to know if the ...
0
votes
1answer
56 views

Generic Wrapper class for HTTPClient methods

I am trying to using HttpClient for making API calls from a different domain and for that purpose I have created the following service class after doing some research. It is 4.7.2 framework and not a ....
3
votes
1answer
205 views

Undo/Redo Functionality in DataGridView c#

I have looked at many topics related to this topic, but I could not find or understand for datagridview table. Finally I made the undo / redo implementation myself using datatable lists. This solution ...
0
votes
3answers
69 views

Statement checker c# using forms and frontend

I'm just here for suggestions and code optimisations, what i could've done better, are there any better coding practices... There's github repo link if you're interested in the code with a form too ...
1
vote
1answer
47 views

Sort and Delete duplicate image files

I'm trying to make a console application to sort and delete duplicate image files. I have a folder with about 20000 images which take up roughly 70GB of space. I wrote the following script and it ...
0
votes
0answers
60 views

ActionableWrapper<T> Creating a conversationservice

So this time I am going to use ActionableWrapper on https://github.com/ScottLilly/SOSCSRPG which is a simple RPG game. The main portion of which is GameSession.cs which is the controller and owner of ...
1
vote
1answer
64 views

Conventional C# for LinkedList with (non-)nullable references + xunit tests

I'm new to C# and would appreciate any feedback you might have on the following doubly-linked list implementation, particularly WRT the following language features: Exception handling Debug.Assert ...

1
2 3 4 5
191