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

ManagementEventWatcher, process monitoring

I'm using ManagementEventWatcher to monitoring some process. It works well but I think the code's kinda repetitive. I was wondering what would be the correct way ...
0
votes
1answer
735 views

Return Lists from Recursive Function C#

I would like to return or save for later use in the ParallelSums function what I currently have printing out to the console in the findAllSubsetsRec function. If I pass the ParallelSums function an ...
1
vote
0answers
96 views

C# User class using SqlServer Database

I am creating my first business application. Unfortunately, I do not have anyone experienced in .NET or c# to review my code, and this is my first time not only using SQL, but also creating code in a ...
3
votes
2answers
448 views

Function that receives a string fraction and has to return said fraction reduced

I got this exercise on a job interview and i'd like to know how can i improve my code. Exercise: Create a function that returns a reduced version of a fraction. Examples Reduce("4/6") = &...
0
votes
1answer
86 views

Getting address with MemorySharp

I'm using MemorySharp to calculate the memory address from a pointer address and then inject values in memory. The code works perfectly, but I was wondering if this would be the right way. I found a ...
1
vote
1answer
197 views

Program to continuously check availability of internet connection c#

I have a C# program to check if a hard coded host is available and if not, waits then checks again (this is a loop in form of recursion). How can it be enhanced? ...
0
votes
1answer
106 views

C# Asynchronous Lock class

I'm wrote Asynchronous Lock provider for reducing lock that breaks async keyword. All tasks with async and ...
2
votes
1answer
134 views

C# A function to make custom requests

This method is supposed to make a custom requests and then get its response. Sometimes, the response is a string, and most the time the response is in JSON format. As far as I know I can't have a ...
1
vote
0answers
109 views

C# Debiasing from Good PRNG

I am in need of a "debiased" clamp function, to generate a uniformly-distributed random number from a good PRNG. Let's assume that RNG in the below code ...
0
votes
4answers
125 views

Calculating sum and count of even and odd numbers (follow-up)

(This is follow-up question). I updated my console program code to calculate sum and count of even and odd numbers. Provided code : ...
6
votes
3answers
1k views

Calculate sum and count of even and odd numbers

Started learning C# second time. I have written a console program to calculate sum and count of even and odd numbers. Provided code : ...
2
votes
0answers
75 views

WPF DataGrid Column FIltering using Behaviors

This is the simplest implementation of the 'DataGridBehavior' Class for column Filtering I could come up with: ...
1
vote
2answers
144 views

Possible speed improvements for a Sudoku board validation algorithm?

I tested this algorithm on 9x9 boards and on average, if the board passed to the function is a (valid) solution, it takes 0.13-0.14 seconds for 1 million executions on my machine. I ran my code in ...
5
votes
0answers
224 views

Multithreaded pathfinding in Unity C#

I've tried to implement multithreaded pathfinding in an attempt to increase performance, but if anything, performance seems to actually decrease when I enable multithreading. Is there anything I ...
1
vote
0answers
55 views

Credit based order system

I'm implementing a system, which requires an order to be active. I have a class called Yritys, which is the customer account who would have credits. 1 credit would mean 1 day of service use. Yritys (...
0
votes
0answers
474 views

Dapper UOW with Multiple Databases

Scenarios / Requirements: I am working on to convert the existing WebAPI Data Layer to Dapper from EF. The following are the ...
3
votes
1answer
92 views

WIP "Console" processor, written in C#

I decided I wanted to make a console-like system. So, I started planning & creating it in c#. Currently, all that it is is a processor of sorts. It reads all bytes from a file (...
0
votes
1answer
576 views

Asynchronous Event Handler

This class acts as an asynchronous event handler that will execute all attached tasks in an async/await context. Requires Nuget Immutables. Example usage: ...
3
votes
1answer
144 views

A versatile deck of playing cards. Standard 52-card deck and more

I have seen many posts regarding a standard 52-card deck of playing cards. I recently was composing an answer to one such post when I realized my answer should be its own post since (A) the answer ...
1
vote
0answers
30 views

User control displaying data which refreshes every 0.125 seconds

I have the following data bindings set up: ...
1
vote
0answers
41 views

Replace SingletonPattern by using IOC Container based architecture

I have a legacy winForms application that now I'm in charge of maintaining and developing. This app has a lot of singleton instance.... Some are very similar to service that wrap other component or ...
1
vote
1answer
96 views

What is wrong with this CancellationTokenSource example

Anybody mind providing an opinion on whether or not this is a good or bad example of Task Cancellation and why. I have my own opinion and I've been told that its baseless, just trying to find out who ...
0
votes
1answer
58 views

Optimizing location updates when adding a new object

I'm trying to keep a bunch of Objects called Machine in their proper order. I was wondering if it'd be possible to further optimize the function ...
4
votes
0answers
75 views

Possible optimization for finding small bitmap in large bitmap in C# without unsafe code?

Background I am creating a tool to locate a small bitmap in a large bitmap by comparing each pixel. Since I am by far no professional programmer, I was searching for some code snippets and found this. ...
3
votes
1answer
99 views

Reservoir Sampling of an enumerable collection of unknown size

I have an enumerable source for which I do not know how big it is. I want to select a random element from it, without having to hold the whole collection in memory and with uniform distribution. I ...
11
votes
4answers
3k views

C# - Standard 52 card deck

I made a 52 standard deck generator for practicing my C#. Just to let you know I am using the unity editor. I would your feedback as to whether my code is good/bad or whatever you may desire. ...
-1
votes
3answers
114 views

C# oop eco system simulation

This is my attempt at simulating an eco system. Basically this thing is suppost to simulate how an eco system works. Its not the most accurate thing but it's something. Let me know what you think ...
-1
votes
1answer
85 views

What would be this best way to show that my function can accept some specific numbers as input? [closed]

I am writing a credit card generator. I have method GenerateVisa() who will return either a 13 or 16 numbers string. This is the default value but GenerateVisa can ...
-2
votes
2answers
65 views

Binary Search Algorithm Difference

As far as I test, there is no any bug point tested. However, I wonder that if there is a problem with the usage of arr.Length or ...
0
votes
1answer
119 views

A C# hangman game

I made this c# hangman game... I would like to know what you all think about it. This is a pretty basic but still gets the job done let me know what you think. ...
1
vote
2answers
111 views

checking is ellipse is filled or not

following code below works fine but feels kind of a mess. Any one has a better way to do this? I am creating a basic "Enter Pin" to unclick screen on an app. So if the user enters the 1st ...
5
votes
1answer
168 views

Can my excel to excel data copy code with some with data manipulation be more efficient?

I'm trying to copy data from a worksheet to another worksheet with some modifications made on the fly. Here are the details of the stuff I'm trying to do: Open the file from where I'm going to copy ...
3
votes
2answers
196 views

Does my passwords generator in C# make sense?

I'm new to C# and I've just created a passwords generator. I'm not sure if my code is following best practices, etc. The schematic of the program is simple. How many passwords of x length can be ...
1
vote
1answer
155 views

C# Coffee Machine

I saw this post and tried to do my attempt. This is the requirement of task: Design a coffee machine which makes different beverages based on set ingredients. The initialization of the recipes for ...
4
votes
1answer
73 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
98 views

Reading data from a CSV and pushing it to a Salesforce application

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

Execute .NET Core 3.1 background worker tasks simultaneously

I have following code: ...
1
vote
1answer
146 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
69 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
54 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. ...
6
votes
1answer
285 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
72 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
43 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 ...
2
votes
1answer
97 views

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

I've got this algorithm that's "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 ...
2
votes
3answers
71 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
118 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
81 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
97 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
97 views
1
vote
2answers
80 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 ...

1
3 4
5
6 7
196