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

How can I create generated clickable text which calls a c# function onclick?

How can I call the function and get the element ID from within the function? ...
-1
votes
0answers
12 views

What's the best practice element to use when allowing selection in C# website?

To display text where each word is selectable. Which Html element is recommended to surround each word. I would like it to be visible to the user and underline when selected. Then, a submit button ...
0
votes
0answers
11 views

Advise to optimize the following code in a better way

I have some data stored in a dictionary where the values are basically a list of objects with few attributes in them. Right now I'm looping through as following to get the data stored in a specific ...
1
vote
0answers
49 views

Implementing a Most Recently Used Cache

I want to create an In Memory Cache in .Net. The primary usage for this cache would be to store addresses... I want to keep around 1000 addresses in memory and once the cache is full, remove the Least ...
1
vote
0answers
43 views

Class to wrap result or exception, similar to the OneOf approach

I recently came across the OneOf<T0,...,Tn> package from mcintyre321 via a video by Nick Chapsas, which presents the idea of holding exception types to be ...
3
votes
1answer
119 views

Snakes and Ladders OOP

I've created a simple Snakes and Ladders game. The goal is improving my knowledge about OOP.There are some basic rules. I need to be able to move my token. The token starts in the square 1. If the ...
2
votes
1answer
103 views

Is my approach to bubble sort correct?

Following is bubble sorting code. I tried bubble sort after reading theory. Please let me know if my solution is correct and if so anyway I can make it more efficient? ...
2
votes
1answer
61 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
172 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# ...
-2
votes
0answers
21 views

Unity, How to use one function on several different buttons [closed]

How to make one method can be used in several buttons so that it doesn't get an error ...
0
votes
0answers
27 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
58 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
152 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
79 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
164 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
46 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. ...
2
votes
2answers
317 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
86 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
127 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
88 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
59 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 ...
2
votes
1answer
62 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
50 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
141 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
96 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
78 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
136 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
131 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
68 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","...
1
vote
1answer
65 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
105 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
78 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
109 views

Parse meter readings from CSV file

I have a class representing meter readings: ...
1
vote
0answers
45 views

One class that exists only to initialize instances of another class [closed]

If you have this inheritance: ...
0
votes
1answer
96 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
65 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
126 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
100 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 ...
3
votes
1answer
126 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
41 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
71 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
85 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
71 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
66 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
64 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
123 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
81 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 ...
0
votes
0answers
21 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
184 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
2 3 4 5
194