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

How to call repository methods in EF core so caller can know what it returns [closed]

How to make good repository in layer so caller od repository methods knows what method returns. If I have Student and Grades objects in database I can have one query: ...
6
votes
3answers
419 views

StringTokenizer for .NET Core

Splitting a string in tokens is a more complex topic than String.Split() wants to make us believe. There are at least three common policies according to which a string might be interpreted and split ...
2
votes
1answer
42 views

A method that calls multiple async tasks with error handling, done the right way?

I've got a method, CheckForValue(), that uses named pipes to send a message to another process running locally, and then receive a message from that process, ...
2
votes
2answers
49 views

Entity Framework Core verify SaveChanges count

I am using ASP.NET Core 3.1 and have been assigned a task to verify the count of changes done using SaveChanges(). It is expected that the developer should know how ...
6
votes
1answer
81 views

Making an alphabatical list grouped by letters

I have a pet project (open source on GitHub) that I built as a learning exercise. It is a lyrics web application built in .NET Core MVC. On the artists page of the site (view on mobile size viewport, ...
-4
votes
0answers
35 views

What is best practice for structuring my C# project? [closed]

I'm working on a service client. Currently I've got the following folder structure. Runner calls and injects into the ServiceClient class in the ServiceClient.cs file. ...
-3
votes
0answers
20 views

Solving a variable with a cross product but it doesn´t give me consistent results [closed]

I have two curved lines that I´ve simplified into a sum between a vector and a vector multiplied by t, which is a time variable that goes from 0 to 1. These two lines are connected at the same t time. ...
5
votes
3answers
90 views

Creating a CSV stream from an object

I have this code that gets a CSV string from a list of objects where the first row in the string is the object's properties and the rows underneath are the properties values. I then create a ...
2
votes
2answers
101 views

Adding some wait time between API requests to avoid overloading the server

In Shopify a product can belong to a collection. I have written a method which accepts an organisation. It would then get a list of collections that this organisation has from Shopify. Finally, it has ...
-1
votes
1answer
56 views

Model return List object [closed]

I have a ViewModel where objects are all string and the model from the database Address is a list. I wanted to know if there is ...
4
votes
1answer
93 views

Proper Error handling when we expect results from secondary functions

I'm building an android application and I have some second thoughts on some error handling case. I have a method that gets data from the internet by calling this method: ...
1
vote
1answer
84 views

C# extension method to do some action if a target operation takes too long time to finish

I have a potentially long running operation and I want to trigger some action if takes too long time. Also I want to reuse this logic. Operation to check: ...
3
votes
1answer
47 views

Creating a simple event message passing system in C# for a rudimentary 2d sprite game

I am currently experimenting a bit with C# and as a way of learning I am making a very simple 2D game (asteroids-ish). I am using the monogame framework and the general plan of attack was to have all ...
2
votes
1answer
69 views

Iterate through a list of data and add it to nested models

I have to go through files with metadata and I am unhappy with the iteration and how I have build it due to the fact, that I have a modeltree with lists. So basically I iterate through ...
2
votes
0answers
71 views

ASP.NET Core 3.1 Multi-tenant with separate database

I am following this sample by Gunnar Peipman to create a multi-tenant architecture in my ASP.NET Core 3.1 application. It is working as expected up to the point shown in the sample. ...
7
votes
4answers
874 views

IService<T> or defining IProductService, ICustomerService

As per tutorial here, I have the following classes: (In reference to this tutorial's section) ...
4
votes
1answer
103 views

Updating items in a list from a blocking source asynchronously

This is a Windows forms application. this.Server.GetLogMessages() will block if there are no messages to get, so I want this in a separate thread. I'm putting the ...
2
votes
0answers
62 views

Marching Square algorithm

The following source code is a solution to the Marching Square problem. The explanation of using random numbers in ambiguous cases can be found here. ...
1
vote
1answer
43 views

ScraperWorker: Refactoring large method?

This class works as a single instance of a worker, a worker reads from a bank of queue items from a MySQL database table, although that logic is abstracted into ...
2
votes
0answers
32 views

C# Color implementation with conversions from RGB to HSL and CMYK and vice versa, targetting Blazor and CSS

This is an implementation of a Color class, primarily targetting the web to be used in a Blazor app. Color.cs ...
3
votes
1answer
58 views

Over overloaded method

I am using SignalR to send notifications to clients. I use IClientProxy which is a proxy for invoking hub methods. It has 10 overload methods for ...
2
votes
1answer
48 views

Multiple producer single consumer on the same thread

I implemented a multi-producer single consumer class, with an important restriction that once the consumer started working, it must continue its work on the same thread (the reasoning behind this is ...
3
votes
1answer
46 views

C# KeyNotFoundException with more information

Preliminary rant: System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary. Oh. My. So I finally got fed up with how ...
2
votes
1answer
53 views

Different versions of the Operate method

I have code that basically is the same, but depending on the number of arguments you provide (up to 5), it will operate with them in a very repetitive way. I have the feeling that this can be ...
1
vote
0answers
24 views

Xamarin: ToggleBar control

Heyhey, I'm attempting to implement a ToggleBar control for Xamarin as there is non up to date and fully customizeable. Now I haven't implemented too many controls and while the control is not fully ...
3
votes
1answer
70 views

CRUD integration test, is it ok?

I want to test my CRUD operation to a MySql database (I use dapper as my ORM). This is what I wrote with ...
2
votes
2answers
81 views

concatenate string, with different first and last iteration

Good day. My code works but I think there is a better way to do this. Like string pattern or string manipulation. I'm not yet familiar with both terms. The goal is to get "=A1-A2-B3-D4-WHATEVER ...
2
votes
0answers
92 views

Windows user form to fill data to be sent to MySQL database

I have created an application to send data to MySQL. On top of that, I am attaching a file and storing into a folder. Also, If trying to attach an excel sheet - another form opens, giving you the ...
3
votes
2answers
133 views

C# One type to represent multiple types (including generics)

Our monolithic WinForm application is getting a face lift. One current challenge that we are restructuring how we setup events. I rolled my own event manager class to handle the subscriptions and ...
10
votes
2answers
2k views

Programmatically close optical drive tray

I really liked the close tray program that CD-ROM drivers programs used to include in MS-DOS days. Since I live in a place where even getting an internship is impossible, I've decided to learn by ...
3
votes
0answers
88 views

Poker Game: Building a console menu

I'm working on a menu for my poker game console app. I've conceptualized the menu(s) as a class with menu items that have their own position. I would like to get pointers on how I could improve on ...
2
votes
0answers
25 views

Uploading CV file to an e-commerce website and sending the CV to employer's email

I am working on an e-commerce website. In this specific scenario, people can upload their CV to apply for a job. The job application is sent to ApplyForJob action ...
3
votes
1answer
99 views

Finding the possible number of equal pairs in an array

I got this test online last week. here is an example: given this array: { 1 , 2 , 4 , 5 , 1 , 4 , 6 , 2 , 1 , 4 } on condition that index(x) < index (y) find the number of possible pairs (x,y). ...
3
votes
2answers
153 views

Build byte array from multiple different types of data for sending over a network

The following codes purpose is to generate an array of bytes that represents some user defined data. This array of bytes will later be used for sending over a network. ...
1
vote
0answers
46 views

ILogger with Delegate Callback

My code writes data and then receives data back. I want to log that this has happened, and I also want to inject a delegate so that I can get a callback to trace the data that is going in and out. ...
2
votes
1answer
84 views

Bruteforcing passwords

A day ago I started a c# project where I bruteforce passwords. Passwords can be both integers and strings. In the code I check how many characters the password has. Whilst this is kinda cheating it ...
-2
votes
2answers
59 views

How can I refactor a function to be inline? [closed]

I'm refactoring functions trying to do more of a in-line aproach. ...
5
votes
4answers
163 views

C#: Repeated String

From HackerRank "Repeated String" challenge: Lilah has a string, \$s\$, of lowercase English letters that she repeated infinitely many times. Given an integer, \$n\$, find and print the ...
2
votes
1answer
47 views

How do I make multithreading in sending large file from FTP to Azure large files faster

Currently, I have a code which downloads a file from FTP to local hard disk. It then uploads a file in chunks to Azure. Finally, it deletes the file from local and ftp. This code is very slow though. ...
-1
votes
1answer
75 views

How would i optimise this if statement [closed]

Im finally done with my project and im going through my code and optimising it and trying to cut down on the chunky lines of code, how would i optimize this, it a series of if statments that matches ...
2
votes
0answers
113 views

Making 90% similar code for 20 different objects

Basically, I have 20 very similar objects and most importantly I want to do the same thing for all of them. This is the ImportProcessor class for ...
3
votes
2answers
75 views

Exporting objects in various formats while reporting progress

Description A WinForms application has a function to export objects of the following type, in various formats: ...
8
votes
3answers
1k views

C# Blackjack prototype

I would like some feedback on my code, I'm new to coding with C# but I do have some knowledge on Lua and Python. Is there anything that I need to change/clean up to make it more simplified? ...
1
vote
1answer
59 views

Photo browser WPF app - performance improvements

I'm working on WPF photo broswer app as a personal project. I realise my current strategy for thumbnail handling is poor as I read in the full image each time -- this shows when browsing a folder with ...
1
vote
0answers
18 views

Adding multiple child entities to a parent entity when creating the parent entity

I have a form on a page to add a Post (parent), before submitting the form, a user should be able to add 1 or more Sections (children) to the Post. The form: ...
1
vote
2answers
50 views

ASP.NET Core async iactionresult

I am new to async methods and am kinda confused how async is working so what i want for you to do is review this code and tell me does implementing async like this is meaningless ...
7
votes
2answers
454 views

WinForm Logon Best Practices

I have a working logon for a WinForms Project. I use the program.cs file to launch the login form. I am not so sure there isn't a better way of implementing this. ...
3
votes
1answer
76 views

JSON serializable string enum in C# with generic JsonConverter

How can StringEnumeration be changed in the code below into a generic class, so that ConsensusState wouldn't need the ...
3
votes
1answer
120 views

Abstracted email sender with content providers

I've created an email sender with providers for the email content, that will be changed based on the email type. I need some help to enhance it. These two models are used to send ...
4
votes
1answer
59 views

Merging and sorting overlapped intervals

We are given an array of intervals we need to merge all overlapping intervals and sort the resulting non-overlapping intervals. When they "touch" in a single point, intervals are also ...

1
2 3 4 5
186