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

IEnumerable<T>.Tee implementation

I am trying to write A C# version of a method in the Java Stream API called Collectors.teeing() (It's like Aggregate but with multiple accumulator functions), just for educational purposes. I want to ...
  • 1,170
2 votes
0 answers
37 views

2-Player Chess in WinForms V.2 (With Separation of Concerns)

Introduction After getting initial feedback on my first working version of this Chess WinForms game here, I have used the suggestions and comments from there to come up with this new version, trying ...
3 votes
0 answers
32 views

Building an API for an e-commerce system to allow third party software to import products

I am working on an e-commerce website called Shopless, which is similar to E-bay/Gumtree. Our website integrates with other DMS systems, in order to allow organisations to import products into our ...
-3 votes
0 answers
23 views

How do i get the value of a dictionary object in <string,Object> [closed]

the dictionary as returned by an api is Dictionary<string, object> dict2 = new Dictionary<string, object>(); the items in question resides in the ...
3 votes
2 answers
61 views

Algorithm to find sequential ID gaps in List<long>

I had to develop an algorithm that will find gap between sequential Ids within a List<long>. For example as input we had the following ...
  • 131
0 votes
0 answers
31 views

Copy object without reference using reflection

Recently I was in need of a method to copy an object and pass it to a method which alters the data. Since a class is passed by reference this would alter the class in the caller which I don't want. So,...
  • 101
3 votes
1 answer
68 views

Unit of Work & Repository Pattern - Injecting UoW into Repository Base

Description I am implementing the Unit of Work & Repository Pattern with Dapper as my ORM and PostgreSQL as the relational database. I have seen examples of UoW where: The UoW class creates an ...
  • 31
0 votes
0 answers
25 views

Pass an object to itself as a parameter, or not? [closed]

Here are two versions of more or less the same code. I'm interested in feedback on which to prefer. Version A: ...
1 vote
0 answers
70 views

Optimizing a EF Core "upsert" operation

I'm trying to "optimize" the command below. In other words, to make it suit my needs using best practices. I found a lot of posts regarding the "upsert" operation and there were a ...
  • 677
2 votes
1 answer
76 views

Engine that performs certain amount of ticks per second

This class will fires a certain amount of ticks per second. I would greatly appreciate any suggentions, I'm more then welcome for any feedback since I haven't coded for long in C#. It is intentional ...
  • 23
1 vote
1 answer
72 views
+50

Algorithm to compare OAuth2 Rich Authorization Requests

Authorization Requests spec defines new authorization_details parameter. The authorization server have to somehow compare this parameter to decide whether client ...
1 vote
0 answers
45 views

Generic Method Response from c# methods [closed]

I am trying to write a generic method return for all the methods on my project across all classes like ...
2 votes
2 answers
91 views

Exponential retry handler implementing DelegatingHandler in C#

I am writing a small library where I don't want to include Polly since I want to keep the number of dependencies as small as possible. I also thought it was a good learning exercise to do this on my ...
  • 143
0 votes
1 answer
62 views

Write SQL Server table to Parquet file

This is a C# console application that creates Parquet file for SQL Server table. Given a 5GB SQL table, it takes nearly 65 minutes, so for our bigger tables (up to 500GB), it may end up taking days to ...
  • 1
-1 votes
0 answers
47 views

C# Implementation of LinkedList without internet

I'm studying for level 4 apprenticeship and I need to learn about all datatypes and general programming techniques. LinkedList is one of them. Once reading about it I decided to implement it myself ...
1 vote
4 answers
117 views

C# decomposition and refactoring of a very long Web Data Scraping Function with multiple different tasks using a Clean Architecture Pattern

I inherited a very long and messy C# function with a task to make it more readable and Clean Architecture Pattern friendly. The primary goal of a function is to send an API request to an endpoint and ...
3 votes
2 answers
125 views

2-Player Chess in WinForms

Introduction I decided to program a two player Chess game in C# windows forms to help me to improve my programming skills and OOP skills. I have come to a working finished program (as far as I can ...
5 votes
1 answer
59 views

Waits for one of two xpaths to be present, one inside of an iframe, one outside of it

I'm using selenium for testing, and I've written code that waits for one of two locations before it continues. This is really easy when both locations are within the same frame, because then I can ...
7 votes
3 answers
834 views

C#: SnapchatUsernameExtractor

I have written a small class that works in extracting Snapchat usernames from common conventions of sentences, manipulating the positioning of certain characters to hopefully extract a valid username. ...
  • 91
1 vote
0 answers
54 views

Extend the login timeout in a ASP NET 7 application

My ASP Core web application was recently upgraded from NET6 to NET7. Almost zero problems except one, which still puzzles me. With the "old" NET6 version, once an user log then app in (...
3 votes
2 answers
254 views

Detecting Intersections of a Collection of Singly-Linked Lists

I was recently presented with the following coding exercise as part of a job interview... Linked List Intersection Question You are given a collection of singly-linked lists(SLLs). Return true if any ...
  • 487
4 votes
2 answers
123 views

Reading S3 files from two different buckets but adding it to one list variable

I have a below code which reads all the S3 files from a particular S3 bucket and then it adds all those files in a ...
  • 43
4 votes
1 answer
117 views

Bouncing balls program with speed up/speed down boxes and lines which change direction of ball

I'm new to C#, background in Ada, C. This is my second lab in a course, output works correct but I feel like I've missed something about OOP. I've asked for feedback from lab 1, but didn't get any. ...
  • 53
5 votes
4 answers
2k views

Dividing two numbers then handle the divide by zero exception with try/catch

I am new to coding, I hope you can help me to improve my code :) First of all: The code works correctly. ...
  • 53
1 vote
1 answer
72 views

Request-response model over sockets/websockets

This is a request-response model over sockets/websockets (like HTTP) where you technically match request id to response id and return the response. In addition to that, there is timeout in case that ...
  • 677
2 votes
1 answer
66 views

Saving entity containing complex jsonb column with validation and comparision

I've been a .NET Developer for almost 4 years. I'm stronly learning and trying using design patterns and following SOLID principles for 3 months right now (I know - a little late, but better late ...
  • 23
5 votes
1 answer
115 views

C# console app to subscribe to Chuck Norris API

I'm a newbie when it comes to programming. I'm working on a console app that subscribes to ChuckNorris JSON API and displays the results. I believe I took into account all possible scenarios. Do you ...
2 votes
1 answer
103 views

Serilog logging extension methods

I've been using this extension in almost all of my projects. What's your opinion? Do you think there is something else to add or to be improved? The idea is to ignore all default ASP.NET messages that ...
  • 677
2 votes
1 answer
138 views

Retrieving large batches of online game codes?

In my current solution, a user triggers my web API from a web application of mine first, then my web API calls a 3rd party web service, and the results/codes are displayed on the web application. In ...
  • 37
7 votes
4 answers
852 views

Calculate average values for each day of the week for each Meter

I have a program with these two methods. One method to import a set of data from a CSV within the given time period and store them in a dictionary. Here the data in CSV file is stored in following ...
6 votes
3 answers
257 views

Intersecting rectangles on a torus

Description Imagine a space like the arcade game Asteroids where everything wraps around right to left and bottom to top - effectively coordinates on a flat torus. The diagram shows an example of two ...
0 votes
0 answers
49 views

Using System.IO.Pipelines to read binary protocol with Start/Stop Flags

I need to read data from a binary protocol with the following properties: The data is proceeded with a single byte start flag. The data is terminated with a single byte end flag. The data will not ...
  • 161
1 vote
2 answers
145 views

Geting file-names from the current working directory

The following routine returns the file-names from the current working directory: ...
1 vote
1 answer
90 views

Web scraper for e-commerce sites Part II

I asked the same question Web scraper for e-commerce sites yesterday and I'm now posting the revised code here. I'm building web scraper application which takes name, code and price from few sites. I ...
  • 23
4 votes
2 answers
748 views

Brute-force Integer Diophantine equations solver

I want to improve the performance of my equation solver So I have an expression:- 42a + 75b - 30c + 80d + 25e + 50f, let's call it ...
  • 115
0 votes
1 answer
123 views

Web scraper for e-commerce sites

I'm building web scraper application which takes name, code and price from few sites. I thought factory pattern would fit in my application. I would like to someone review my code and tell if I ...
  • 23
2 votes
4 answers
304 views

CSV to list, map to database

I have a code block that imports CSV to list and map to a database. And there are few validations and I've to return error messages based on those validations. Right now all those logic is handled by ...
  • 131
0 votes
0 answers
29 views

Modified PoC for BlogEngine.NET CMS (CVE-2019-6714)

This is a modified exploit proof of concept targeting the BlogEngine.NET content management system (CVE-2019-6714) for the .NET framework. I modified it (from Cobb 2019) to execute payloads via ...
  • 101
0 votes
0 answers
72 views

Is this a good implementation of Dependency Injection using MVVM without any nuget packages?

So I've been looking into dependency injection for WPF while still using an MVVM pattern. And something that's been incredibly difficult to wrap my head around was, how to create a navigation service ...
  • 101
1 vote
1 answer
54 views

WinForms Most effective way to Rearrange Custom Controls in a FlowLayoutPanel?

I am creating a video parser in C# WinForms. You select files, they get parsed then a custom control (ViewWideNarrow ) is created showing the video's name, duration and so forth, which is then added ...
4 votes
1 answer
240 views

Abstract base class for binary serialization

Ensuring that some logic is always being run before the user's overriding methods. I'm writing a library and I have some abstract classes that can be binary serialized (and users can subclass them and ...
  • 409
3 votes
1 answer
190 views

Generic Integer Square Root

I have implemented an integer square root function that is branch-free and runs in constant time, using the first variant found in this answer as a base. All possible values for the types ...
  • 1,870
0 votes
1 answer
61 views

Copying multiple SQLite database files between two locations

Is this fastest and most reliable way to copy multiple database files (SQLite) from one location to other and overwrite them if they already exists, safely ? Currently I'm using the below approach : <...
  • 101
4 votes
1 answer
106 views

Implement DRY principle with IAsyncDisposable

This is a tiny class that creates backup copies of a file so these can be diff'ed to spot the changes compared to last run; used when generating code and so far has proved to be very helpful. ...
  • 582
1 vote
1 answer
99 views

Dining philosophers problem using just lock without semaphore in C#

I am trying to solve the Dining philosophers problem in CSharp. I didn't use any semaphores and it looks like it's working. I am wondering 1) if my code deadlock is safe and 2) if can I please get ...
  • 389
1 vote
1 answer
78 views

Prototype design pattern

As a practice and self-development exercise I have decided to implement design patterns in C#. I am using polish cuisine as an example in my implementations. In this project I implemented Prototype ...
  • 169
1 vote
1 answer
74 views

Singleton design pattern

as a practice and selfdevelopment exercise I have decided to implement design patterns in C#. I am using polish cuisine as an example in my implementations. In this project I implemented Singleton ...
  • 169
1 vote
1 answer
84 views

Choose item from list

I wrote small console application where you can choose an item from given list of strings. Works fine so far but since I am beginner I have some questions if I am doing this right. My biggest concerns ...
1 vote
0 answers
58 views

A service that downloads the whole trade history off an exchange and involves Redis cache

This service is pulling off the whole trade history for the Binance accounts. More precisely, it's a wrapper around https://binance-docs.github.io/apidocs/spot/en/#all-orders-user_data. Since their ...
  • 677
1 vote
0 answers
51 views

Spell checker using levenshtein minimum distance

I implemented a simple spell checker. Basically I have to user input an incorrect sentence or a word, then a number N, and then N correct words each on new line. The program has to output "...

1
2 3 4 5
200