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
3 views

Call a window application from another window application

I have the feeling this question is for "Code Review" but it could be a question for "Stackoverflow" because this is also a general question about coding and way to manage the ...
-2
votes
0answers
71 views

Refactoring overkill? C# example [closed]

Say we have two operations that make http requests. ...
1
vote
2answers
66 views

Database dynamic query

I am working with C#, Npgsql, EF Core and Postgres. I ...
2
votes
2answers
59 views

Simple MemoryCache implementation for thread safe caching

After much prompting from this post I wanted to build a simple, in-memory, thread-safe cache. The only caveat (as far as I was originally concerned) was the need for two different absolute expiration ...
0
votes
2answers
47 views

Factoring out common elements of an email transmission routine

I wrote some code and realized they share similar logic. I am struggling to share the logic and welcome any suggestions. ...
3
votes
2answers
106 views
+50

Implement IDisposable correctly using object composition principle

Is it possible to implement IDisposable pattern correctly while using object composition principle to promote code-reuse, reduce code duplication and hide verbose &...
3
votes
0answers
71 views

Simple Leaky Bucket Async and Low Footprint

I'm working on a simple Leaky Bucket algorithm. I have found a lot of samples on the internet, but something always bothers me. Most of them use Collections and DateTime to track current actions and ...
-1
votes
0answers
17 views

Path to a file in windows service [closed]

In my Windows Service Solution I had to add a json file (the same level as the appSetings file) which I had to read and write into. I know that ...
3
votes
1answer
94 views

Hangman game with only one word

This is a hangman game. The only word is 'word' and I am not planning on changing this since I am not going to publish this game or anything. If there is any unnecessary/bad code I need to get rid of, ...
1
vote
2answers
76 views

Configure service with user-related parameters in .NET Core dependency injection

I have service class which loads data from external service. This service needs API key which loads from db and unique for every user. ...
0
votes
2answers
95 views

is this a good way of using events?

So I'm currently trying to learn more about events using C# and the example that I just write seems a bit.. It seems a bit too much? I feel like you could accomplish the same thing with way less code. ...
0
votes
0answers
60 views

Download File Service

This is my code for download file process. The codes is working fine but would like some code review. Any comment will be appreciated especially on exception handling part. Should I just need one try ...
1
vote
1answer
64 views

Copy vehicle information from JSON list to relational database

I am looking for suggestion to make my for loop iterate faster. With about 2000 rows of data. Below code is taking lot of time to run. So far I have followed various Stack Overflow answers. For ...
1
vote
3answers
93 views

Is this method for loading data in a C# application recommended?

Goal I'd like to understand if this current method, of loading data and inserting data into a database I currently use is to be avoided? Code I drafted a simple application that loads data and inserts ...
1
vote
2answers
193 views

Using multithreading to send multiple emails

I'm trying to send any number of emails in the shortest amount of time using .NET 5.0? I've been playing with something like the following but I am not sure if it is optimal or even correct as there ...
0
votes
0answers
62 views

Validation in Web Api layer or Service layer

I have this method in Web Api layer. ...
2
votes
2answers
88 views

Print Binary coded decimal Numbering of a given input number

Example 1 input:3 output:0011 Example 2 input : 15 output: 1111 in the below example code 15 is input. I have taken 8 4 2 1 as array for Binary coded decimal numbering this code is working as ...
0
votes
1answer
48 views

An async time-based rate-limiting semaphore for C#

This is a class that allows only limited number of requests to proceed per period of time. This is designed for use with external APIs that require such rate limiting, e.g. 600 requests per 10 minutes....
0
votes
1answer
55 views

Concatenating two possibly null strings with a separator

I have two strings (aggregatePath and pathFromParent), either of which might be null or an ...
0
votes
1answer
90 views

How do I optimize my GetChildren method

UPDATED I have a POCO class that is populated with _context.Categories.Load(): ...
3
votes
3answers
997 views

Printing rotations of an array 7 times

Loop through a given array 7 times and print the following output: int[] arr = { 9, 2, 7, 4, 6, 1, 3 }; ...
2
votes
1answer
73 views

A simple C# script that exploits PHP command injections

Back in 2016, I wrote a simple C# script that exploits a generic command injection vulnerability on PHP webapps, just for the sake of demonstrating that exploits can be written in .NET languages (due ...
1
vote
0answers
40 views

Embedded services using chain of responsibility?

I currently have a few "worker services" that wrap existing code to automate incredibly repetitive code. A few examples are: Method analytics. Iteration support. Exception logging. My ...
3
votes
1answer
62 views

Posts data to endpoint, trying not to use .Result on async methods

I have a Send method that is working but want to refactor a portion where it is using PostAsync().Result and ReadAsStringAsync().Result. I've never written async methods before and don't feel I ...
0
votes
0answers
52 views

Find the number of different submasses in a weighted string

I'm using a site similar to SPOJ (in Portuguese, so I don't think linking it will help), where I need to find the number of different submasses in a given weighted string. Through the use of an ...
1
vote
1answer
56 views
4
votes
1answer
87 views

More efficient way to create an ASCII maze using box characters

I've written a C# program to generate a random maze, and then draw that maze in the Console mode using box-drawing characters, e.g. ─ │ ┌ ┐ ┬ ┼ etc. It works fine, as below, but I'm not convinced that ...
1
vote
1answer
55 views

Best practices in regards to pass and deserialize data, when calling an API endpoint from a MVC-project?

In my application, I only show users their own data. For that, I need to know in the backend, which user is requesting data. I use the username for that and therefore, I need to send the username as ...
4
votes
0answers
82 views

License-holder editing application

I am building a WPF (Windows Presentation Foundation) application. And I'm trying to use the MVVM (Model–View–ViewModel) design pattern. It's fascinating and rewarding, even though it seems overly ...
1
vote
2answers
90 views

Combine elements of two lists into another list

I have two lists, I need to make another list with the same elements than the other lists. But elements on this list need the next sequence. list1[0], list2[0], list1[1], list2[1], ... and so on for ...
1
vote
1answer
59 views

How to continiously read data from a NetworkStream

So I'm currently learning about networking between a client and a server and I decided to try to write my own client and server. I implemented a way of receiving data and it goes as follows.. The ...
0
votes
1answer
113 views

Good practices for a class

I was working in a class, but there are a lot of things that I'm not sure if they're a good practice or not. For example, the => instead of the ...
1
vote
1answer
44 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
118 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
89 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
403 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
67 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
80 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
58 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
126 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 ...
0
votes
0answers
101 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
121 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
739 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
30 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
133 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
107 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
53 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
95 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
87 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
101 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: ...

1
2 3 4 5
193