Questions tagged [c#]

C# is a multi-paradigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform.

Filter by
Sorted by
Tagged with
0
votes
2answers
47 views

Finding the next available filename

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

Enhance Performance C# [on hold]

I have the below code that performs well until input size reaches 1000. After that, it takes more than 2 milliseconds to finish. Any help? ...
5
votes
1answer
60 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
41 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 ...
1
vote
1answer
34 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...
12
votes
1answer
998 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
162 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
5answers
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
116 views

Creating custom objects with custom properties using generics

I have two base classes: City and Building: ...
6
votes
3answers
730 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 ...
-4
votes
0answers
36 views

Skip day when there is no store opening in C# [on hold]

I am trying to create a program that will skip the days when there is no store opening on that day. Ex: Day 1 -> Friday DAy 2 -> Saturday Day 3 -> Sunday (no store opening) Day 4 -> Monday ...
1
vote
0answers
44 views

Some questions about a simple asynchronous socket client [on hold]

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
96 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
121 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
319 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
0answers
35 views

How to Keep alive code? [closed]

I've a code for merge multiple txt files into a single txt file from click on start button. Now I want to keep this code alive till code stopped by the user. ...
4
votes
2answers
472 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
94 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
0answers
59 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 ...
0
votes
0answers
52 views

LINQ join columns from several DataTables into same column from another DataTable [closed]

I have no big experience with C# and it is my first query in LINQ which I have to write. But in my opinion what I wrote is not clear to read and it is ugly. I will be grateful for any help to make it ...
2
votes
1answer
150 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
38 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 ...
-1
votes
0answers
53 views

c# Heap and Stack Cheatsheet [closed]

I'm attempting to create a Cheatsheet that explains where a variable is allocated on creation. Let me know if I,m right or wrong, or if im missing something crucial. Thanks. Link to Gist ...
4
votes
3answers
169 views

SkipLast of an IEnumerable<T> - Linq Extension

As my answer to this question, I came up with this solution: ...
1
vote
1answer
68 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
113 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
84 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
749 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
189 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
0answers
34 views

Optimizing a complex list in C# [closed]

Need to improve the while loop performance. In my code I'm using for loop and create new instance for every loop. It takes around 25s to complete. How to boost the performance? Here is my code snippet:...
1
vote
1answer
84 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. ...
1
vote
2answers
117 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
116 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 ...
4
votes
4answers
490 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
43 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
37 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
59 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
94 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
76 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 ...
1
vote
1answer
137 views

Do these BLL-DAL comply with the Dependency-Inversion Principle and is this valid Dependency Injection?

I am working on a very simplified proof of concept (POC). Separation of concerns should be achieved in this project, so that in the future we have flexibility in respect of what data source we use (...
-4
votes
0answers
14 views

GetMessageAsync MailKit or Use own MultiThread Task [migrated]

Can I use my own multithread method to retreive message does IMAP respond if I send like 50request for UniqueId Or will it only respond to 1? How does GetMessageAsync work and how do I get the ...
-2
votes
0answers
43 views

Common notification service for email and SMS

I have a notification service for sending email and sms notification.I have this interface for notification to get notification by notification id Send notification ...
0
votes
0answers
19 views

c# Httpclient singleton with different authentication header [migrated]

I have an azure function that calls API and I made my HttpClient as a singleton in the startup Dependency Injection so I can call it on my contractor. ...
4
votes
1answer
61 views

Passing Array into Unmanaged Code for Modification

I have an array allocated in C# which I am passing into unmanaged code to be modified. The following code works, but I am not sure if there are any other more '...
3
votes
2answers
83 views

codekata: Binary search on an int array

I'm following Karate Chop kata for a binary search. I really wanted to avoid built in functionality within the language. I'm pretty new to C# so any recommendations is greatly appreciated. Spec: ...
1
vote
3answers
65 views

LeetCode:implement strstr C#

https://leetcode.com/problems/implement-strstr/ I implemented Rabin-Karp algorithm https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm please review for performance, also if you were in an ...
2
votes
2answers
107 views

Find all possible words in a board of characters

This question has 2 possible solutions and I am trying to implement the DFS solution. Here is the Trie and DFS solution: Boggle using Trie and DFS Please review for performance. Given a ...
3
votes
1answer
52 views

Asynchronous hardware communication - Library Design

I've got some equipment ("tool") that communicates over CANbus that I need to communicate with. I'm using a USB->CAN dongle that provides a basic .Net control library. I'm in the process of writing ...
2
votes
1answer
20 views

Force ConcurrentDictionary in a Singleton Registry to Collect Removed Items/Space

I have the following class which is used in a WebApi AspNetCore application as a singleton instance to store Strategy objects (reference type). The class is ...