2022 Developer Survey is open! Take survey.

Questions tagged [.net]

.NET is a software framework supporting a multi-language paradigm and supporting language interoperability. .NET applications are executed in a virtual machine (CLR) which provides a few important services: security, memory management and exception handling.

Filter by
Sorted by
Tagged with
1 vote
0 answers
61 views

Implementation of Concurrent List in .NET

I would appreciate review of this implementation of the concurrent list that is, to my knowledge, currently missing in .NET Core. Requirements Thread safe Lock free Ordered Supports get and set by ...
user avatar
  • 111
2 votes
1 answer
52 views

Managing websocket subscriptions

The following code is pulling data off an exchange. It keeps the subscriptions to the channels because when the websocket client reconnects, all subscriptions are gone and we basically need to ...
user avatar
  • 423
3 votes
1 answer
68 views

Console Slot Machine written in C#

This is my console simulation of the Slot Machine in C#. Please take a look at this code and point out possible ways of improvement. ...
user avatar
  • 39
1 vote
0 answers
44 views

Specification pattern vs Always valid domain model [closed]

Let's say we have two aggregates: ...
user avatar
-1 votes
0 answers
43 views

Re-designing the response type of a method. Instead of throwing exceptions, put these exceptions in an Error property

I'm trying to improve SendAsync because of how ugly it looks, for ex. look at EnsureAuthenticated. I don't like the fact that it throws exceptions when it fails to ...
user avatar
  • 423
1 vote
1 answer
117 views

General web socket client with auto reconnect capabilities

This is a web socket client wrapper with auto reconnect capabilities. First of all, I know I should avoid working with strings to reduce allocation, that's on test purpose. So, ignore the fact that it ...
user avatar
  • 423
0 votes
0 answers
33 views

Abstract instance creation for handler

My application uses several data sources. One is a web-service, the other uses a database context, and in some cases even files on servers have to be retrieved. I am trying to find a way to ...
user avatar
0 votes
1 answer
80 views

Reading and modify big set of data

I have a method that iterate over my table question in database and then will split a column commentaires and finnally put ...
user avatar
  • 143
3 votes
1 answer
210 views

Convert a c# decimal to big-endian byte array

Following the avro schema documentation for decimals I've created a method to turn a decimal into a byte array. The goals are: Should be represented by a non-scaled integer Should be big-endian I've ...
user avatar
  • 155
1 vote
0 answers
39 views

F# thumbnail Scraper

Thumbnail Scraper I'm a C# programmer learning F#. For my first program I created a console youtube thumbnail scraper. It parses command line arguments with argu and then downloads the thumbnails, ...
user avatar
1 vote
0 answers
90 views

Replacing multiple substrings in C#

There is a String.Replace method in C# and it is 1-1 mapping replacing operation, i.e. single Unicode character / string source replaced with another single Unicode ...
user avatar
  • 3,302
3 votes
2 answers
173 views

Reading big csv file C#

I'm trying to read quite big file with around 28 million of rows in the following way: ...
user avatar
2 votes
0 answers
69 views

Is this a valid implementation of Memento Pattern in C#?

I've been studying design patterns from GOF for a few weeks, especially in C#, and I'm struggling with Memento Pattern. I know there are a lot of C# implementations on the web, but I came up with my ...
user avatar
1 vote
3 answers
135 views

c# record parameter validation technique

This comes from an answer I provided to a question on stackoverflow here: https://stackoverflow.com/a/71482194/3258131 To make c# record parameter validation concise and maintain all the benefits of ...
user avatar
  • 45
2 votes
2 answers
57 views

Concise handling of async tasks with timeouts in c#

Often I have async functions that I want to be able to time out, this timeout is independent of the greater scope of the application. However the function should also take into consideration the ...
user avatar
  • 45
1 vote
4 answers
98 views

Multiple if statements in a single method to enable/disable feature

I am sure this is not ideal code, basically I am checking a condition at a time and exiting if any of them are true. This will then disable refund functionality. ...
user avatar
1 vote
0 answers
67 views

Caching wrapper with multi-providers and factory to detect the responsible cache provider related to Type

What I'm trying to do abstract the caching actual cache provider (memory || distributed || ...). enable a caching diversity. each cached item type has different ...
user avatar
  • 151
1 vote
1 answer
137 views

How to process multiple background concurrent Tasks in c#

I am trying to work out the best way to go about a task which relys on multiple long running tasks taking place. My use case is that I want to have multiple events running for set periods of time, ...
user avatar
0 votes
0 answers
81 views

.Net Request ServerVariables

In my controller I have this model which has IPaddress. I created this method GetUserIP taking in the HttpRequestBase request ...
user avatar
  • 109
0 votes
0 answers
50 views

Is this valid MVVM when clicking an item to open a new window?

So I'm currently playing around with WPF and MVVM and I've been trying to find a way to select an item in a list and display it in a new window. And I came up with a solution that I personally like ...
user avatar
  • 119
8 votes
1 answer
1k views

Card Shuffle without using any help C#

I'm new to C# but not 100% new to development. I wanted to try writing a Card Shuffle + Card Dealing algorithm using as least as possible inbuilt functions or any libraries and no internet use to ...
user avatar
0 votes
0 answers
63 views

ISO Xml Serializer for .Net API Controller

I've created a pretty simple XML input formatter, that inherits from XmlSerializerInputFormatter, that is able to serialize XML input that is ISO-8859-1 encoded. I created it, so that I do not have to ...
user avatar
0 votes
0 answers
128 views

Is there a faster way to read bytes with a FileStream?

So I'm trying to read data and store it in an array as fast as possible and the fastest method I found of doing so was this. ...
user avatar
  • 119
1 vote
2 answers
110 views

IPAddress Range access

I want to make this code better and easier to read. It works now but I think it can be better. When there is an Inbound request I check to see if that accessKey is setup for IP address Range that will ...
user avatar
11 votes
7 answers
2k views

How much error handling is too much?

I have the following C# code (.NET 6): ...
user avatar
  • 794
0 votes
1 answer
56 views

Action on each element of an inline list

I'm trying to learn the "functional" part of C#/.Net for work, and I'm not sure if this is a good way to write this statement. I was also trying to reduce duplicated code while not ...
user avatar
1 vote
1 answer
143 views

.Net BouncyCastle - PKCS#3, PKCS#8 & PKCS#10 Generation as base64

Reaserching BouncyCastle for C# is not for the faint of heart. After navigating an ocean of Java dead ends, I have arrived at the following code. I believe it's very useful for someone who wants to ...
user avatar
5 votes
1 answer
407 views

C# Async FileInfo Extensions (Copy, Move, Delete)

Here is my effort to implement extensions for FileInfo object: ...
user avatar
  • 151
3 votes
1 answer
205 views

Deque class for .Net (C#)

As .Net has no Deque class (Double-Ended Queue) in the Frameworks and I couldn't find an example implementation that I was happy with, I have written the following with the intent that I may post it ...
user avatar
0 votes
0 answers
62 views

Calculate offset and fetch values

The calculatePage function - Calculates if a parent and child comment have more than 15 comments then consider it as page. The next 15 comments should be moved into the next page. The logic works fine....
user avatar
  • 101
0 votes
0 answers
79 views

Wrapper around SignalR's implementation

I made a web socket client wrapper using SignalR's implementation, but there are some downsides that I want to improve. CancellationToken's implementation is wrong/incomplete ...
user avatar
  • 423
1 vote
0 answers
84 views

.NET Repository Pattern

I'm currently in the process of defining some framework, one of the first things that I thought I could start with was defining some repository pattern/layer. I generally wanted some input on it, ...
user avatar
3 votes
1 answer
253 views

C# duplicated attributes on Azure Functions with OpenAPI specifications

I'm developing a REST API using Azure Functions with .NET 5 (Isolated) and I want to add an OpenAPI spec for each route. But it looks like this: ...
user avatar
  • 329
1 vote
1 answer
61 views

Best approach to combine repositories logic

Let's suppose I have 2 repositories: first is responsible for creating job and return jobId second is responsible for creating ...
user avatar
0 votes
1 answer
175 views

Custom Binance API wrapper around IHttpClientFactory

I made a custom Binance API wrapper (BinanceRestClient) which uses IHttpClientFactory in order to prevent socket exhaustion, ...
user avatar
  • 423
3 votes
1 answer
181 views

Learning Sockets in C# (.Net Framework), Suggested Improvements?

I'm just learning how to allow interconnected apps via Sockets, watched a tutorial last night and based on that this is what I've gotten: Server.cs Code: ...
user avatar
  • 177
1 vote
1 answer
105 views

Unittesting in .NET 6 with XUnit

I'm trying to learn and write best practice unittests and practice test driven design. Can you give me some tips and review my code? ...
user avatar
1 vote
1 answer
74 views

BigByteList with a managed wrapper

I am a novice when it comes to C++ (as well as C++/CLI). I am trying to write a minimal 64-bit implementation of a List in C++ (using unsigned __int64 as the index ...
user avatar
0 votes
1 answer
53 views

Entity Framework - component shop using polymorphism and generic repository

I am creating a .NET Framework MVC EF application for PC components. I wanted to make full use of inheritance, polymorphism and generic repository pattern - but was wondering if my initial design ...
user avatar
1 vote
1 answer
100 views

Find and replace all substrings in a string

Given a list of strings paragraphs and words. Check each paragraphs's item for containing <...
user avatar
0 votes
2 answers
216 views

Slow method that works with IEnumerable<dynamic> as input and return value

I have this method that returns an IEnumerable list , it takes 5 seconds to execute , so I want to know how can I optimize it side performance time of response. ...
user avatar
  • 143
-1 votes
1 answer
125 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. ...
user avatar
0 votes
1 answer
125 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 ...
user avatar
  • 1,796
1 vote
2 answers
162 views

Using a IEnumerable where we have mostly only one item

I have a project where I publish and subscribe some data packages. Mostly those data packages are just one package, but sometimes (1 in 100) there could be more packages at one time (a lot more, like ...
user avatar
  • 165
0 votes
0 answers
111 views

ThrottledStream

Need a ThrottledStream for a project, created the following class (still not tested), wouldn't mind some opinions on the code and suggestions on how it can be ...
user avatar
  • 171
1 vote
0 answers
69 views

Simplify LoadLibrary/GetProcAddress helper for dynamic parallel DLL instantiation

Code is meant to be used in Windows .NET (tested with dotnet5.0) to dynamically load C library and return delegate of given function Code lower is result of my attempt to rewrite the ...
user avatar
2 votes
2 answers
511 views

Simple MemoryCache implementation for thread safe caching

After much prompting from this post I wanted to build a simple, in-memory, thread-safe cache. The only caveat (as far as I was originally concerned) was the need for two different absolute expiration ...
user avatar
  • 157
4 votes
3 answers
268 views

Implement IDisposable correctly using object composition principle

Update at the end Is it possible to implement IDisposable pattern correctly while using object composition principle to promote code-reuse, reduce code duplication ...
user avatar
  • 93
3 votes
2 answers
192 views

Hangman game with only one word

This is a hangman game. The only word is 'word' and I am not planning on changing this since I am not going to publish this game or anything. If there is any unnecessary/bad code I need to get rid of, ...
user avatar
1 vote
2 answers
251 views

Using multithreading to send multiple emails

I'm trying to send any number of emails in the shortest amount of time using .NET 5.0? I've been playing with something like the following but I am not sure if it is optimal or even correct as there ...
user avatar

1
2 3 4 5
25