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

replace substrings from within Hebrew text

I have a string of Hebrew text which also contains":", "-", & "|". Attempting to replace "-", "|", and ":" with a space. How can I do ...
0
votes
3answers
193 views

C# 'out' keyword in JavaScript [closed]

Since I met the out keyword in C#, I'm trying to find an equivalent in JS. So, please take a look at the code and leave your opinions or suggestions about this. C# ...
0
votes
0answers
32 views

Accessing and changing Application scope Settings from separate project

After many different approaches and attempts I arrived at this method to set application scope settings for my applications: ...
0
votes
2answers
65 views

List of objects inside same model vs Factory vs Service [closed]

I am creating a simple Country class. This Country have list of know countries. we can get the list of known countries Country.AllCountries, ...
3
votes
2answers
164 views

Print a Menu in the Command Line following SOLID

Problem Description I am building a library that helps me building TUI Apps more faster, for example printing TUI Menus and other components. I would like to get feedback on my design decisions to see ...
0
votes
2answers
128 views

Time complexity of generating Pascal's triangle

This is LeetCode question 118 Pascal's triangle. Given an integer numRows, return the first numRows of Pascal's triangle. There is an example. Input: numRows = 5 Output: [[1],[1,1],[1,2,1],[1,3,3,1]...
3
votes
1answer
208 views

Timer for event throttling

I have the following problem. I want to write a class that handles events and passes it through but reduce its number if there recently was an event. Basically it is debounce. However there is a ...
0
votes
1answer
55 views

Simplify this code that adds string representation of class members to a List [closed]

I have a bunch of code that adds the string representation of members in a class to a List. ...
3
votes
2answers
365 views

Asynchronous and recursive word square generator in C#

Overview I've created an asynchronous and recursive method of generating word squares, of any size (known as the order of the square), from a known word list. If you're unfamiliar with word squares: ...
2
votes
2answers
91 views

Algorithmic Efficiency: GetShortestUniqueSubstring implementation

I came upon this Youtube video and the problem they discussed piqued my interest, so I decided to take a stab at it. Below is the question: Given an array of unique characters ...
-1
votes
2answers
144 views

DiscountManager class in C#

I built a class in C#, DiscountManager, which is responsible for calculating a customer discount based on years of loyalty. I want to refactor it and am seeking any ...
0
votes
1answer
108 views

Whats the best way to refactor a POCO class

In work I was asked to fix a bug which involved me making changes in a class. To fix the bug I needed to add a collection of a class that looks like this. ...
0
votes
0answers
70 views

Gilded Rose with pure functions in C#

Gave myself the challenge of solving the Gilded Rose with pure functions in C#. All one-line lambdas, all static, all the time. The original kata assumed the code would mutate the given array-- I've ...
3
votes
1answer
68 views

Using the Decoder class in a streaming context

Am experimenting with the IAsyncEnumerable interface and PipeReader class. Have come up with the following to decode a stream of bytes into chunks of characters and am able to decode all of my test ...
0
votes
0answers
66 views

Improving the Speed of loading records into a ngx-datatable

I am using ngx-datatable to load large volumes of records. However, the larger the volume, the longer it takes. I read somewhere that you can speed it up by sorting then assigning it to the data ...
0
votes
2answers
151 views

Method if condition logic

This logic checks accessGroup and if accessGroup is equal to "Admin" then it only checks if result.Admin or baccess is true but if accessGroup is anthing else it will need to check two other ...
0
votes
1answer
109 views

Linked List Implementation in C#

I wrote an implementation of the Linked list data structure. I mostly did this because it's the simplest collection data structure (at least the simplest to implement), and I wanted to practice ...
1
vote
2answers
89 views

Is there a way to simplify getting the character that appears the most in a collection with Linq?

I have a collection of strings, all of which are three characters in length: ...
2
votes
2answers
158 views

Fake Interview Scenario: Hangman

For a fake interview I decided to write Hangman. The first question I have is when reviewing someone's code for a job interview is it more important to write something short and sweet that gets the ...
2
votes
2answers
142 views

Best Practice for Button Event Handler

I have a button btnSearch and the event handler btnSearch_Click inside my asp.net web application, using web forms. (certain ...
2
votes
1answer
78 views

Grouping anagrams together from a string array

I wrote this code in c#. It is a question from LeetCode, number 49. Given an array of strings, group the anagrams. The examples it gives are: ["eat","tea","tan","...
2
votes
1answer
75 views

Manual authenticated encryption on .NET Core

I've been tasked with creating some way to encrypt arbitrary text for a .NET Core app, with the following requirements: Messages will be between 10 bytes and 1 kB. Boss doesn't want me to use AES-GCM ...
0
votes
1answer
125 views

Using the repository pattern with Dapper and a single accessor object

We are using Dapper as our ORM and have chosen the repository pattern for organizing our operations. This has worked very well for us but I'd like to confirm that this configuration is capable of ...
-1
votes
1answer
79 views

Calculate certain ratios of "work", "low work", and "no work" over large date ranges

I have the following algorithm to calculate certain ratios of "work", "low work" and "no work" over a set date range (startDate, ...
2
votes
1answer
113 views

Parse meter readings from CSV file

I have a class representing meter readings: ...
1
vote
1answer
124 views

Writing data to CSV, checking for duplicates

I am writing a program that takes user input and writes it to a CSV file. I am also checking to see if what they have input is a duplicate of whatever is in that CSV file. So far, the flow of this ...
1
vote
2answers
71 views

WaitFor method for website automation testing with Selenium WebDriver

I am trying to use Selenium for website automation testing tasks and I am new to Selenium testing framework. The the situation I faced is to wait the website components loading and then do the related ...
1
vote
1answer
140 views

Get result of a scalar-valued SQL function from C#

I do not receive files on holidays; I only receive files on regular days—i.e., non-holidays. I want to skip 2021-09-06 since that's a holiday (Labor Day) and I know I will not receive any files. ...
3
votes
1answer
147 views

Creating a Client-Side Prediction and Server Reconciliation

Preface I have been trying to find out "How to make Client-side Prediction and Server Reconciliation" from scratch with an easy-to-understand code in C#. So I decided to make my own ...
4
votes
1answer
140 views

Brute force to solve refund amount in a payment/invoice domain

I work at a major Swedish insurance company. I'm in charge of a service that matches bank payments with invoices. I will not show the details of that match logic. But one outcome of the match is that ...
0
votes
0answers
46 views

Two sets of scripts for a Katamari Damacy-style game

I would like some feedback on trying to implement SOLID principles to my Katamari Damacy-style game, I have provided below the 'original' script which accomplished a variety of tasks, and then the '...
1
vote
2answers
95 views

Strategy Design Pattern in ASP.Net Core MVC Project

I tried to make a calculator using the Strategy pattern in ASP.Net Core MVC (following an example from the Internet) Please review my code and tell me what could be wrong and how to make it better? My ...
1
vote
1answer
98 views

Performance optimisations using Span<T>

For parsing astronomical datasets (mostly images) I have written a parser that reads .fits files in C# .net5.0. The content part of the file basically constists of a blob (byte array) that holds all ...
0
votes
1answer
80 views

Web Api to upload excel file

I work on asp.net core 2.2 web API using C# language I need to rewrite function below with best syntax and with best practice web API below get Excel file from upload and return Excel file it working ...
0
votes
0answers
67 views

Is my non-blocking collection actually thread-safe?

I've implemented this out of curiosity, and I'd like to know if I've implemented everything correctly, and/or see if anyone has suggestions. This caches some metadata for a game, so: Infrequent ...
0
votes
1answer
66 views

Is my address model too broad or "over the top"?

I'm starting to create data models and one of the models I need should represent a mailing/billing address. While I reside in the United States, I recognize that there are different terms utilized in ...
-2
votes
1answer
124 views

how can i optimize this method [closed]

is there a better way to optimize this piece of code?? I am checking if each item in the collection has property classID , then do my logic. Any better way where I do an enumerate only for documents ...
1
vote
0answers
84 views

How can I make my model translator usage more concise? [closed]

The Problem I'm updating a system to use OOP where a major process of the system is to translate data between many providers. The translations happen in a many to many fashion. So provider A, B and C ...
9
votes
4answers
3k views

Criticize my Sudoku solver for improvements (C# beginner)

I recently started programming and chose C# as my first language. After a couple of weeks/month now I tried to make my own Sudoku solver in a console application. I'm happy with the result, and tried ...
1
vote
0answers
27 views

Verify implementing Microsoft Graph 4.0.0 for SSO in Azure is implemented correctly

I originally posted this on SO, and I know cross-linking is generally frowned upon. But, I am not sure if this falls under question or code review because the code works where I do not know if it is ...
4
votes
1answer
192 views

Enumerating my method to handle any time out issue

I have below code which is going to copy records from one container in cosmos db to another container in cosmos db. I am just worried on not following the best practices and below code might time out ...
1
vote
1answer
116 views

Detecting supported browsers in ASP.NET MVC (Server side vs. Client side)

I want to check client's browser version, and if it's too old, display a message that the user should update their browser in order to use the website. The website is built using ASP.NET MVC. I have ...
1
vote
0answers
48 views

"streaming" messages to a broker from a batch-like source (eg sql database), optionally acknowledge back to the source

I am writing library code to help other developers send messages to a pub-sub event broker. In many cases, the message source will not be "stream-like". Specifically, most messages are ...
1
vote
1answer
87 views

Adding structure to a flattened data model instead of using an interface?

I'm attempting to integrate with a rather dated API (for work so I can't disclose actual naming, endpoints, etc), and their data models for POST endpoints, very clearly implement an interface that ...
-2
votes
2answers
105 views

So many if and else conditions [closed]

I have this class ...
0
votes
2answers
78 views

Efficient way to build table within database or update it using C#

I have a headless application that does either of two things. If table does not exist within database create it and copy all the data over OR If table exists update it Now I usually use access ...
6
votes
6answers
2k views

Is this try pattern to fetch entities from a chess board, easy to follow?

I'm currently writing a game of chess, and, more specifically, I'm creating the code for the game board. The board is simply a static class that contains a multi-dimensional array representing the ...
0
votes
0answers
71 views

How to do kendalls tau in O(n log n)? O(n^2) is shown

I am trying write a method that will calculate kendalls tau in O(n log n) time. I have a managed to it in O(n^2) quite easily however I cannot find any GOOD explanation online that will describe with ...
2
votes
1answer
98 views

Shortest route algo terribly slow

First post. I posted this on stack as well but somebody suggested I post it here too/instead. I wrote a shortest-path script for a Unity game project, and while it works, it gets so slow when applied ...
1
vote
2answers
103 views

Add a folder via JSON

I read about, that I only should have up to two parameters and a function should have about 10 lines. Now I am in trouble to achieve this. It is a Javascript/JSON thing in C#. I have too many ...