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
16
votes
3answers
2k views

ExactlyOne extension method

I often find in codebases something on the order of if (sprockets.Count() > 0) which is easily replaced with LINQ's ...
9
votes
2answers
763 views

Recursive search on Node Tree with Linq and Queue

This code is now maintained on GitHub I've created a Node class which contains two important properties: ...
12
votes
2answers
1k views

Calculating Fibonacci sequence in several different ways

I'm doing an experiment trying to freshen up my unit-testing and learn dynamic programming. Every test passes but I'm curious of the result of some of them and worried if I'm doing the testing ...
2
votes
0answers
62 views

Await data coming from an event [closed]

This is a USB related question, but the problem is not USB specific. When reading data from a USB endpoint, there are two patterns I am concerned with. Request/Response like HTTP (done over the Bulk ...
5
votes
1answer
86 views

Unbalanced search tree for comparing multiple string arrays

I have a system that stores resources. A resource contains a string that represents a user role, for example "3". With this user role "3", you can retrieve a list of permissions for the user role, ...
4
votes
1answer
96 views

Page-by model of data output and search results with values for UI

This is my first experience of designing classes with inheritance. I would like to get feedback on the interaction between the presented classes. It is unlikely that this code will seem complicated. ...
6
votes
1answer
92 views

Tiles Game Best Practices

Coming from a software engineering background I don't have so much experience developing games. Below is a simple 2d tile connect game. What would people improve about it? What are some good practices ...
5
votes
2answers
120 views

PLINQ code analysis in terms of efficiency of cryptographic hashes generation

I have the following code that I wrote in order to find the correct password by generating hashes out of all possible combinations and comparing each of them with the target. I'm trying to make ...
3
votes
0answers
46 views

Optimizing throughput when writing millions of rows with Parquet's row group

I'm building a basic data pipeline in .NET to extract data from tables in our RDBMS systems, that exports into columnar storage using Parquet. I'm using Parquet's row group to batch up the writes into ...
3
votes
3answers
108 views

Unit tests for a function that calculates demerit points for speeding

I'm currently working on a unit testing course (NUnit 3.x). I've been tasked with a simple class to test all edge cases. ...
-1
votes
1answer
77 views

Class Inheritance in C# (possibly generics) [closed]

I'm working on a segment of code where it runs a number of tasks and then combine individual task results to construct a complete task result object, there's no concurrency involved so it's purely a ...
7
votes
5answers
529 views

Grouping into more groups in one iteration

I had a need to group the same dataset in several groups. So instead of repeatedly query the dataset, I made an extension that could do it once. The caveat is, that the result is materialized in ...
0
votes
1answer
164 views

Adding a Node to the Linked List is taking a longer Time when using a reference to the Tail Node

I am trying to add two numbers in the form of linked List and return their result in a Linked List as given in https://leetcode.com/problems/add-two-numbers/ Question: You are given two non-empty ...
-4
votes
1answer
50 views

Generate random letter without repetition [closed]

I have this code but it brings repeated results. I want it to generate without repeating the letters ...
0
votes
1answer
99 views

Abstracting an Email Notification Service & testing the the logic of the used abstract factory

In my application I have an Interface IEmailNotification that represents an Email and the concrete implementations have nothing to do with ...
2
votes
3answers
136 views

Finding the next available filename [closed]

We're having a small debate in work about the following piece of code: ...
7
votes
1answer
101 views

Function to send email, refactored based on SOLID principles

I have the below method that is responsible for generating and sending a MailMessage using a SmtpClient object: ...
3
votes
1answer
106 views

Cancelable AsyncLazy that is thread-safe

I've been thinking about the AsyncLazy<T> class that Stephen Toub and Stephen Cleary present in various resources such as this. I am trying to find a way to ...
3
votes
1answer
62 views

Compare performance of Concurrent Dictionary with Dictionary+Locks

I wanted to measure the performance of Concurrent Dictionary vs Dictionary+Locks in a multithreaded environment. So I created my own SyncDict class of type...
13
votes
2answers
1k views

Asynchronous Circular Buffer in C#

Preamble I want to be able to test methods which communicate over a simple exclusively asynchronous two-way stream-like interface which may underneath use any of a number of communication methods (e....
4
votes
1answer
197 views

Console-based BlackJack in C# - Follow-Up

I have done some code-refactoring of my console-based BlackJack in C#. Finally found a better solution to solve Ace problems (double Aces should be value 22 and third Ace should be value 1). I still ...
11
votes
6answers
2k views

HackerRank: Electronics Shop

Challenge from Hacker Rank - Monica wants to buy a keyboard and a USB drive from her favorite electronics store. The store has several models of each. Monica wants to spend as much as possible for ...
4
votes
2answers
126 views

Creating custom objects with custom properties using generics

I have two base classes: City and Building: ...
6
votes
3answers
841 views

Password maker in C#

I need to generate semi-complex throw-able passwords (just one use) in my application. I want it to be: at least 8 characters long; contains at least 1 digit, 1 [a-z] char, 1 [A-Z] char; I generate ...
1
vote
0answers
88 views

Some questions about a simple asynchronous socket client [closed]

I am having a hard time to come up with a simple TCP client, that should use one socket and two threads (one for sending and one for receiving). As using TPL tasks is the way asynchrony should be ...
4
votes
2answers
105 views

Registering Named services and resolving them by T

Problem statement I have an application that needs to get files from various sources (disk, embedded, http, ftp, ...) so I use a common API for them: ...
5
votes
1answer
126 views

Detecting the presence of multiple URL segments

I have two versions of a function that performs the same task, however I'm not sure which one to use. Speed is something to take into consideration, but I also want to know what the best practice is. ...
5
votes
4answers
580 views

Maximum character insertion

I would like to know any suggestions about to improve my code and/or get a better approach for this problem solution and your rating of my approach to the problem.(besides removing the ...
5
votes
2answers
492 views

Reducing using/foreach/using nesting with a helper extension

Problem statement There are sometimes foreach scenarios that require deep nesting due to multiple disposable objects involved that look like this: ...
5
votes
2answers
186 views

Safe Dispose of Timer

I am currently refactoring a larger solution where the compiler gave multiple warnings about disposing the used System.Timers.Timer instances. The timers are ...
3
votes
1answer
92 views

Use SemaphoreSlim to control access to a resource

We have an existing situation in an MVC ASP.NET app where it's possible for two threads to come back asynchronously, one from an external api(the payment gateway) and one from within the browser for ...
2
votes
1answer
161 views

Checking if an object meets certain criteria to amend to certain Entity Objects?

I am trying to check if a class has only numeric values in it and then return a bool, however, some instances there may be non numeric chars in an object that ...
2
votes
0answers
52 views

Own Authorization attribute

In the existing system, we need to rebuild the user's authorization. The database includes Roles and Rights Roles were previously used but will be skipped in the new version All authorization will ...
5
votes
3answers
239 views

SkipLast of an IEnumerable<T> - Linq Extension

As my answer to this question, I came up with this solution: ...
1
vote
1answer
102 views

Format double to 3 decimal places without decimal separator to a certain length

I need to format a double value to three decimal places to a string with length of 9 with leading spaces and no decimal separator. My approach is this ...
8
votes
1answer
236 views

Console-based ATM client as a class library

I have completed my bank ATM application in C# class library project. For simplicity, the data of this version will be stored in the List instead of a database. The basic feature are Login Check ...
2
votes
1answer
89 views

“Safe” Windows Module API Wrapper

Recently I've been toying around with C# interop and the Vulkan API. Today I discovered the SafeHandle class and decided I'd try to wrap the Windows API calls that ...
9
votes
5answers
985 views

Deck of cards with shuffle and sort functionality

Going through Head First C#'s Chapter 8: Enums and Collections, I learned about List<T>, as well as IComparable<T> ...
5
votes
1answer
199 views

WPF Palindrome Checker Application

I made a WPF Application, called Palindrome Checker, which checks if what you input is a palindrome. Any and all tips on how to make this code better in all capacities are wanted and appreciated. <...
2
votes
1answer
109 views

Union, Intersection and Diff of two sorted arrays in C#

This is the original question https://www.geeksforgeeks.org/union-and-intersection-of-two-sorted-arrays-2/ Given two sorted arrays, find their union and intersection. ...
2
votes
2answers
132 views

Run length encoding in C#

This is the original question: https://www.geeksforgeeks.org/run-length-encoding/ Given an input string, write a function that returns the Run Length Encoded string for the input string. For ...
5
votes
0answers
166 views

Recursive conversion from ExpandoObject to Dictionary<string, object> #2

Because my original question was lacking many details, I have been advised to ask a new question. I will repeat the important parts of the original question and add examples etc to hopefully make it ...
1
vote
1answer
31 views

Optimizing calls for reauthentication by caching tokens and cookies

I am currently developing a REST service in ASP.NET Core 2.2 that acts as a wrapper upon a REST API provided by a reporting solution. The reporting systems REST API authenticates the user based on a ...
4
votes
4answers
711 views

Recursive conversion from ExpandoObject to Dictionary<string, object>

For my blazor library which is a modification of this awesome library I have to convert an ExpandoObject into a ...
1
vote
0answers
54 views

Wordsearch puzzle generator [closed]

I created a wordsearch puzzle generator in C#. It's not a playable game, and it doesn't solve puzzles. Find the entire codebase here: https://repl.it/@blonkm/wordsearch I would like to optimize it ...
17
votes
5answers
4k views

Speeding up thousands of string parses

I have a mapping application which takes string arguments in the form of string arrays. I parse these and then perform an action on the map. One of these is ...
2
votes
0answers
45 views

Managed Vulkan API Wrapper (create/destroy an instance)

I'm trying to follow this Vulkan API tutorial and have come up with an implementation that I don't completely loathe. The VkUtf8StringArray class is my least ...
-5
votes
1answer
64 views

Should method return default true, or false when meeting requirements [closed]

Lets say I have simple IsSomething() method which checks, if object meets few requirements. Which approach is better? ...
3
votes
1answer
106 views

Small application for manipulating users and their activities

I made a small application using C#, SQL Database, entity framework , and windows forms to manipulate users (...
1
vote
1answer
107 views

Boggle using Trie and DFS

I already mentioned in my previous code review, there are two solutions for this problem https://www.geeksforgeeks.org/boggle-find-possible-words-board-characters/ this is the first: Find all ...