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
3answers
59 views

Simpson's method for numerically computing the integration of a function

I have implemented the Simpson's rule for numerical integration. Check this video for the implemented function. ...
3
votes
0answers
21 views

Board Rotation Problem - Best Practices

Problem: You are given a board containing lower-case letters and a word that you have to form. You can only take the letters from the front or the back, hence you have to rotate the board left or ...
16
votes
7answers
6k views

Hacker Rank: Array left rotation

This code is to solve the Hacker Rank problem array left rotation. A left rotation operation on an array of size n shifts each of the array's elements 1 unit to the left. For example, if 2 left ...
3
votes
0answers
378 views

Hosted service for queuing and running tasks in parallel in ASP.NET Core

I am attempting to construct a background service for an IIS-hosted ASP.NET Core project that basically queues tasks and runs them, and I decided to go with the ...
2
votes
1answer
26 views

(Feedback) Finding bridges in an Undirected Graph implementation in C#

I am implementing fundamental data structures in C# while trying to learn techniques in the language to make my code cleaner, more concise while using good programming practices. I have implemented ...
6
votes
3answers
1k views

Reverse each number in a list

I have this method which reverses a list of numbers. For example, if the given input is { 1232, 3455, 6071 }, it will return ...
-4
votes
0answers
30 views

What should I return as response for asp.net core 3.1 web api with ef core 3.0 and repository pattern [closed]

What I am basically asking is that what is the proper way of returning data from a controller implementing repository pattern. Here is the code of my controller - ...
1
vote
0answers
45 views

Awaiting the completion of a server request

I faced the following problem. I have a Server object server which exposes TriggerStateChangeAsync() which return an ...
4
votes
0answers
44 views

Sharing User Inputs via Dependency Injection

This code solves the problem of how to share user inputs throughout a large application when using dependency injection. To achieve this, I'm using a static (through DI) store and injecting it at ...
-2
votes
0answers
18 views

Opening a New Window on a Button click - MVVM WPF

I am new to MVVM architecture, and I would like to keep the standard of MVVM without violating its rules. So I implemented an approach to open a new window on a button click using Services. I don'...
2
votes
1answer
87 views

Group chars in an array if they have the same start and end elements

I am trying to work through this challenge, I have come up with a solution but however I look at the problem statement and the examples provided I cant help but come to the conclusion that the "...
10
votes
3answers
13k views

DbSet<T> IncludeAll method

The Problem As an ASP.NET MVC4 developper, I'm using Entity Framework a lot. Considering performance I often use lazy loading for my models. ...
3
votes
1answer
59 views

C# Quicksort Assignment

For my CS minor I was assigned to implement the Quicksort algorithm in C#. I gave it a go and found that I like the implementation of the algorithm more than Mergesort. Now that I've got my Quicksort ...
1
vote
4answers
192 views

Exercise: Design a Stack

Exercise: Design a Stack A Stack is a data structure for storing a list of elements in a LIFO (last in, first out) fashion. Design a class called Stack with three methods. ...
1
vote
0answers
34 views

How to implement the F# InitInfinite(Async) functions in C# without disabling ReSharper warnings?

When coding in C# I often miss some functions from the F# world. One of them is Seq.initInfinite, others are its counterparts with the ...
9
votes
2answers
3k views

TaskScheduler that uses a dedicated thread

I'm trying to implement a TaskScheduler that runs all tasks in the order they are submitted, on a single dedicated thread. Here's my implementation, using a ...
1
vote
1answer
74 views

Performance: Use plain for loops to look for (existence of) string in string array?

I timed a few ways to look for a string in a string array (with 82 elements in the example) in a case sensitive manner plus ignoring case. I am kind of suprised, that the plain for loops are faster ...
0
votes
1answer
57 views

Inheritance with Singletons [closed]

The problem / background I have a project, BusinessProject, that currently stores some static data in memory using the Singleton pattern - we'll call this class ...
-3
votes
1answer
87 views

Does my code follow good clean code conventions? [closed]

Here is a class that I have implemented in order to sort rows of parameters in the form of an array of strings. ...
2
votes
0answers
27 views

API Layer ClientId and Security style

Im at the point where I am designing my api security and I was going with a custom attribute I don't want to use third party systems as they cost money. I was going to use the client id and the ...
-2
votes
0answers
25 views

Design decision for clone scenario [closed]

As part of my application, I am maintaining a cache which is structured like below, ...
-4
votes
0answers
20 views

List always stay empty after recursive call C# [closed]

I am confused by this problem, why my IList type variable res always stay empty after each recursive call. After calling "res = new List(tmp);" the res should has value However, right after return ...
1
vote
0answers
25 views

Looking for any enhancements to avoid a stackoverflow exception in a C# program [closed]

The program below results in a stackoverflow exception in C# for the input provided. I am trying to see if there are any enhancements that can be made to avoid the stack-overflow. When using BFS ...
7
votes
4answers
28k views

Passing an array of values in Url.Action

I need to pass an array of values in Url.Action. Currently I'm doing: ...
3
votes
1answer
50 views

Save on typing while using UTF8 encoding

Typing in something like Encoding.UTF8.GetString(...) and Encoding.UTF8.GetBytes(...) everywhere in your code could be ...
4
votes
1answer
72 views

C# MineSweeper Game using winform

I designed a game with trying to use solid principles. What changes should I do for making program more extensible, readable. Thanks in advance. Cell class ...
6
votes
2answers
517 views

Microsoft Outlook add-in to automatically save generated report

This is my first C# project, so feel free to be brutal. :) I have an automated external process on another machine generate and email a budget report to me every Sunday. This program is a ...
5
votes
2answers
426 views

TapeEquilibrium implementation

I took a test at Codility called TapeEquilibrium. The task description that I received can be seen here. I came up with a solution that worked, and I was pretty happy with. However, the performance ...
-1
votes
0answers
34 views

Execute async task in constructor [closed]

I've been playing around with this style and wanted to get other opinions on it. I know others have mentioned that you should design your types for async calls so you don't block the async call in a ...
3
votes
1answer
94 views

Speeding up HTTPS API Call helper method

I am having severe problems with performance on a WEB API helper method, the performance is simply dreadful, 1-2 connections / second, I am trying to make 40k API calls and 5 hours later it is still ...
9
votes
2answers
5k views

Query Builder pattern with use of FluentApi

Recently, I've come up with an idea of building a custom query builder combine with FluentApi. Expected usage: ...
7
votes
1answer
151 views

C# random math questions project

I made a C# console math project where the user answers addition, subtraction, multiplication, division, power or square-root questions based on the difficulty they choose! However, I am struggling ...
1
vote
0answers
17 views

LeetCode: Search a 2D Matrix C#

https://leetcode.com/problems/search-a-2d-matrix/ Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row ...
2
votes
0answers
59 views

Java's AtomicInteger equivalent in c#

I'm trying to replicate Android's GenerateViewId() to assign a unique Tag to dynamically created UIViews in Xamarin.iOS. ...
0
votes
0answers
27 views

Handling disconnected entity scenario in Entity Framework Core

As some you you may know, handling disconnected entities in EF can be a bit of a headache. After a really long weekend, I managed to make it work for my use case and refactor the code to the best of ...
2
votes
1answer
75 views

simple implementation of List in c#

...
-2
votes
0answers
46 views

tic tac toe written in c# [closed]

my first project in c# (i already code in python so any help in migrating to c# is appreciated) had a little trouble with 2d arrays vs jagged arrays but nothing a little SO can't fix ...
1
vote
1answer
44 views

Dictionary or custom Collection

I have a list of rule names coming from .xml file. These rule names needs to be validated against rule names in database (Validator.cs). If valid, then ...
1
vote
1answer
85 views

LeetCode: Divide Array in Sets of K Consecutive Numbers C#

https://leetcode.com/problems/divide-array-in-sets-of-k-consecutive-numbers/ Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into sets of ...
2
votes
1answer
54 views

Best way to replace Urls in .Net application-C#

I have an application developed in ASP.NET Core C#, where according to a configuration it must replace certain urls of a text when an http request is made and the text must be returned as soon as ...
2
votes
1answer
27 views

Send Data from DynamoDB to Lambda (C#) and to Azure Queue

I am a beginner and trying to send data from AWS DynamoDB to Azure Queues. Note that this code will be invoked 10,000 and alot more. Can you guys review it once. ...
2
votes
1answer
41 views

Specifying UTC time or current time offset

What do you think about this helper class to specify UTC time? It should also support an easy way to capture current time offsets. Let's say we expose it in API like this: ...
3
votes
0answers
91 views

Taking a screenshot of a particular window

I've got a function which takes a screenshot of a particular window. It's important that the screenshot works whether the window is focused/covered by other windows or not, hence why I've used ...
7
votes
2answers
979 views

HKDF Implementation in C#

Based on my prior question about HKDF here https://crypto.stackexchange.com/questions/43933/use-of-pbkdf2-when-no-access-to-hkdf and the responses I received I decided to go ahead an implement HKDF ...
5
votes
3answers
263 views

CompressSearch algorithm

I Rewrote all code, aimed at a variable reduction, and reduced complexity. removed all extraneous code unnecessary to the operation, reduced indexing surfaces, tests all work consistently. Added ...
3
votes
1answer
2k views

If a regex match is found assign it to a variable

I am searching a string for a pattern that matches Material=. Some examples are Material=ABC123,Color=444555, ...
2
votes
1answer
85 views

Cross-thread label countdown

Short and sweet... I wrote a cross-thread method that displays the countdown [in seconds] of a delay on a label. I'm fairly confident it's far from optimal, so I'm in need of that glorious ...
3
votes
1answer
90 views

Writing pure functions but have a chain

I'm trying to play around with Godot to learn C# and I was trying to creating pure functions to do the velocity, but I found I was repeating myself. ...
2
votes
1answer
47 views

First attempt at Mars Rover Kata done in TDD

I have had an attempt at the Mars Rover Kata and would very much appreciate a review and any suggestions to improve. MessageParser to parse incoming messages and create the domain models: ...

1
2 3 4 5
180