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

Entity Framework optimization when using transactions

I want to save NUnit local tests in a mysql database hosted in Amazon RDS, and I'm wrapping up everything in a transaction like so : ...
-2
votes
1answer
46 views

How to avoid multiple if-else statements to make the code more readable and clean? [closed]

I have the below C# (.net core 3.1) code with multiple if-else conditions which makes the code looks more complex, unreadable, and ugly. Can anyone suggest to me an efficient and cleaner way to ...
-4
votes
0answers
13 views

C# Async Server/Client Multiple Messages [closed]

I have this async server-client code which can send only one message right now. Can you please review it and help me, how to send multiple messages? I want something like a unique Sender class, but ...
1
vote
1answer
28 views

Basic Beginner Unity Project with a bouncing corona

At first I wasn't really proud of this one, but then I decided that I need to know what's so bad about it? Why does it feel unsatisfying? How can I do it better? So yeah here's a unity project that ...
2
votes
0answers
56 views

How to efficiently execute multiple async calls in parallel to cassandra in C#?

I am working with Cassandra where I am getting some stuff out of it using Datastax C# driver. Below is my code which interacts with Cassandra db and in my GetAsync...
2
votes
1answer
34 views

Testing an action returns a View with a ViewModel using xUnit and Moq

This is my first test, I think it's testing what I need it to test but wanted to get some feedback. I wanted to test to make sure the controller action returns a view with a certain ViewModel. The ...
2
votes
0answers
23 views

Email Service - Sending an email with azure blob storage Version 2.0

Now implemented changes suggested in my previous post and now am back again for the internet to tear me and my shitty code down. PatchNotes Extracted templateRetriever class from the email service ...
0
votes
1answer
49 views

given ints 1-9 count the ways unique sets of 3 add up to a given sum

Given a range of integers, count the number of ways each single integer can be used in unique sets of three operands that all add up to a given sum. For a technical interview I was asked to solve a ...
3
votes
3answers
113 views
1
vote
2answers
88 views

Protein Translation - Translate RNA sequences into proteins

RNA can be broken into three nucleotide sequences called codons, and then translated to a polypeptide like so: RNA: "AUGUUUUCU" => translates to Codons: <...
-1
votes
3answers
68 views

Less code vs More readable

I was rewriting some code from my colleague and I was questioning if I was improving the code at all. My take at the code: ...
0
votes
1answer
40 views

Email Service - Sending an email with azure blob storage

Here is some code that sends an email using Mimekit for .net C# to send email via Office365. DI is done using TinyIOC. It downloads an image from blob storage and then sends it with an attachment. ...
-3
votes
0answers
25 views

Why my code always get exception? [closed]

Hi I am working on a project in c#. I am using async task to perform parallel activities. But when I execute my code, it always ...
-1
votes
0answers
56 views

Hotel survey to increase customer satisfaction [closed]

I am new to programming and produced a survey that generates specific responses based on the ratings that were given. Does this code follow common best practices? Can it be written more efficiently? ...
2
votes
3answers
77 views

Is it fine to typecast from one implementation type to another while using an object?

I've a simple code base with few 'weapon' concrete classes which implements different contracts in order to be used by its clients. My contracts: ...
3
votes
0answers
90 views

C# code for minimizing the sum of an array by dividing it's elements (repetition allowed) by 2 for k times

The assumption is that k is quite large as compared to no. of elements in the array and division by 2 returns ceiling of the result. Request for your review and suggestions for further improvements ...
10
votes
3answers
813 views

Roast my C# birthday code

So this is a pretty simple code, I think it was? It asks for the user's birth day and month, and gives it back with the day a discount reminder email will be sent (the day before their birthday) Now ...
2
votes
0answers
30 views

Reactive .NET retry policy

I haven't found a good code example for a reactive retry operator with a retry strategy that was good enough for my needs. So I tried to make my own. It seems to work in my tests but I would really ...
3
votes
1answer
92 views

Mass file renaming via regex

I have over 2500 files in a directory tree- some of them are numbered, some of them aren't. eg. ...
2
votes
2answers
42 views

Simple c# for-loop program for calculating theoretical earnings from investing (beginner)

I am new to programming and "programming thinking" as well. I have created a simple program that calculates future earnings from investing. It seems to be working correctly, but I want to be sure and ...
1
vote
1answer
26 views

Compare 2 directories for equality

Currently, I'm working on a legacy application written in .NET that does not contain any unit tests. This application, when executed produces a very large directory tree with roughly 20.000 files in ...
2
votes
0answers
44 views

Uploading files through streaming with SignalR

I want to upload files from my Javascript client to my WebAPI. With this I want to have a progress bar. My Idea was to cut the files up in chunks and then stream them via SingalR since we are using ...
0
votes
1answer
44 views

A collection of tasks and their CancellationTokens

I have a task wrapper which stores tasks, their CancellationTokens and of course their names (botName). ...
3
votes
1answer
144 views

Amending code to make it list some files in a directory, rather than all

The method list_all() is the code I am starting with. It just lists all files in "c:\windows". I want to adjust it to list only the first 10 files (if there are as ...
2
votes
3answers
104 views

MultiDictionary implementation C#

Because C# .NET does not come with a MultiDictionary, I implemented one based on this StackOverflow answer. The MultiDictionary ...
4
votes
3answers
243 views
0
votes
1answer
19 views

ASP.Net Core API JsonPatchDocument

Hi I am creating a website for my chiropractor and I am creating the API for data access. I am creating a HttpPatch Method and want to know if this is the right approach so would be grateful if you ...
0
votes
2answers
43 views

Collection base on year

Can someone please review the code and suggest any improvements / changes? Note that this method works but wanted to see if there is a better way to reset the currentYearMeetingCount to -1. I just ...
-2
votes
0answers
30 views

Breaking Single Responsibility + how to add promotion in later stage

I had a problem statement and my solution satisfy the requirement but I do not think it is good solution as it breaks Single responsibility requirement.Can someone suggest any better way to achieve ...
0
votes
0answers
32 views

Sharing credentials in C# to be accessed by different classes

This is just a sub-question from one of my other questions: WPF login screen and share username and access id across other forms Aim: I am aiming to log in using MySQL database in C# WPF and share ...
1
vote
2answers
50 views

WPF login screen and share username and access id across other forms

Goal: Goal of this application is to sign in using MySQL database and across the forms access the username and access id. Reason I am sharing the username is for only reason at the moment, is to ...
-2
votes
0answers
54 views

Generating unique list of random numbers in C# [closed]

Can someone please review the code and suggest any improvements / changes? Note that this method works fine for the range of 100000 items. Thanks in advance. ...
3
votes
2answers
139 views

Overloading == for better readability

I was working on a project recently that had a good amount of business logic associated with status codes. To better understand the flow of logic in the domain layer, I created an enum ...
0
votes
1answer
58 views

Run a timer while waiting for user input [closed]

I am making a C# console maths test where the user answers maths questions. I am trying to add a timer to the test, I have managed to make a timer but when I run my code it becomes a mess! Here is ...
1
vote
0answers
50 views

Identify clickable area in a big panel

I have a panel that has 4 images per row and a lot of rows. Each image has a 15 pixels separation and are 250,250 each. Here is a screenshot: I'd like to be able to click on a picture and identify ...
2
votes
1answer
44 views

Enum conversion to Enumeration class with small Business Logic inside

I had old enum, I converted it to Enumeration class and added one method inside (isValid). I am not sure if it is good approach ...
0
votes
2answers
121 views

Double switch C#

I see in old code two function that uses same switch like this: ...
2
votes
0answers
43 views

Sharing model for different ORM's

I am building a MySQL to Realmdb converter app. I use Entity Framework to deal with MySQL, so below is the code of one of my model classes. I don't want to have multiple classes representing the same ...
4
votes
3answers
123 views

DistinctCount extension method

Here I go again. I have been finding a fairly common pattern in business logic code. And that pattern looks like this: ...
1
vote
1answer
49 views

Invoking subscribers of an action in parallel c#

I have a questions as to the proper way to structure the code below. This snippet of code is used within a socket class which is intended to be a high performance socket. Many data handlers subscribe ...
2
votes
1answer
70 views

Nesting IAsyncEnumerable

I am trying to work around the problem Pass-through for IAsyncEnumerable. The best I have so far is to return IAsyncEnumerable<IAsyncEnumerable<T>> ...
0
votes
2answers
66 views

Iterate dictionary object efficiently in c# with pre defined keys? [closed]

I have a dictionary that I need to iterate efficiently. I already know about the keys beforehand which I need to extract from values dictionary object. What's the ...
3
votes
3answers
140 views

Robot Name - Exercise

Robot Name Manage robot factory settings. When robots come off the factory floor, they have no name. The first time you boot them up, a random name is generated in the format of two ...
0
votes
1answer
58 views

My simple implementation of a DI container

I decided to make my own light DI container. I know about Zenject, etc. I wanted a very light analog. I'm concerned about a few things: 1) is it correct to use struct instead of class for reference ...
1
vote
0answers
36 views

DDD design: Tracking price calculation progress and fallback price calculation

I am pretty new to DDD, so any help/ideas will be appreciated. I will explain my initial design and problem below. The user can ask the system to generate products proposal, proposal is basically ...
1
vote
2answers
70 views

PreserveIds using inheritance id db auto incrementing

I am working on this project where I like to PreserveIds once inserted into the database. The id are auto incrementing and I return them once the data in inserted. I like to know if there is a better ...
1
vote
1answer
74 views

Initialize bunch of variables in constructor by extracting value from dictionary

I have a headers dictionary value being passed to one of my constructors and based on that dictionary value I am extracting individual headers I need and setting ...
0
votes
1answer
83 views

Re-factorize a program using single responsibility principle - SOLID- SRP

The class WalkingData storages a "date" and a "walked distance". The class also read the stored data. ...
0
votes
2answers
43 views

How to refactor code to abstract data from a complex object into a single object without using foreach statements

I am trying to abstract data from a complex and create a EventDto. And I was able to do it using foreach but the syntax is dreadful. Is there a better way of writing this code? ...
4
votes
5answers
278 views

Find greatest number in array that is a product of some two elements in the same array

Given an array a, find the greatest number in a that is a product of two elements in a. If there are no two elements in a that can be multiplied to produce another element contained in a, return -1. ...

1
2 3 4 5
182