Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

New answers tagged

1 vote
Accepted

Multithreaded tcp server accepting two clients with task factory and graceful shutdown

In this post let me focus only on the TcpServer class. I will post another review about the TcpClientTwo class next week. ...
user avatar
  • 5,560
2 votes

Recursively search directories and their subdirectories for images and videos, except system or locked folders

Let us first target the comment Why do you recreate and sort the iDontWant collection every time when someone calls the SearchDirectories method? – Peter Csala yesterday and let us only check about ...
user avatar
  • 49.9k
1 vote

ASP.NET Web API for currency

I would remove filtering/paging (.FirstOrDefault(), .Skip() etc...) logic from CbrCurrencyController actions. This work should ...
user avatar
5 votes
Accepted

Managing websocket subscriptions

If you would replace the List<Subscription> + lock combo inside your ...
user avatar
  • 5,560
4 votes

Returning the other value of boolean enum

How about simply just this? => (PlayerMode)((CurrentMode + 1) % 2); Here you are taking advantage of the underlying values: 0 and 1. UPDATE #1 I think if you ...
user avatar
  • 5,560
5 votes

Returning the other value of boolean enum

I think a method would be better than a property in this case. However, I would do it this way : ...
user avatar
  • 4,503
4 votes

Returning the other value of boolean enum

First, kudos to you for using an enum even though it would be very tempting to just use a bool in its place. Not enough can be ...
user avatar
2 votes
Accepted

Split large strings into parts by last index of character and by max length

since your method is for requests payloads, you need to use memory-friendly approaches. I don't know how often the method would be called, and how much requests at average your application would ...
user avatar
  • 4,503
0 votes

Console Slot Machine written in C#

Here are my refactoring suggestions: SetMachineColor vs constructor Depending on your use case it might make sense to set the ...
user avatar
  • 5,560
0 votes

Calculate sum and count of even and odd numbers

Sure it's good. I think loops in this case are not needed. The following is based on the famous: 1 = 1^2 1+3 = 2^2 1+3+5 = 3^2 ... Included the loop so you see how ...
user avatar
4 votes
Accepted

Split string by last occurence of character within a range

You can use the index and range operators instead of SubString calls ...
user avatar
  • 5,560
0 votes
Accepted

Get a list of the 25 most popular items on an E-Commerce site

Sorry for the late post. I did find a solution. The Foreach loop in my original question was making a database call for each item. It worked but it was painfully ...
user avatar
  • 475
0 votes

Naming a method that gets the next enum value or starts from the beginning if the given value is the last

This is not exactly the answer you are asking, about naming, but this implementation contains some implementation ideas on performance and correctness. Essentially, it collects all the enum values and ...
user avatar
  • 803
0 votes

Async/await in Parallel.ForEach

.net6 now supports Parallel.ForEachAsync https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.parallel.foreachasync?view=net-6.0
user avatar
2 votes

Naming a method that gets the next enum value or starts from the beginning if the given value is the last

This method has some counterintuitive behaviour in special cases: If the enumItem is not found in the list, then the method returns the first element of the list. ...
user avatar
6 votes
Accepted

Naming a method that gets the next enum value or starts from the beginning if the given value is the last

The key phrase you're looking for here is cyclic(al) (I prefer cyclic over cyclical but this is subjective). My suggestion is therefore GetNextCyclicValue. You can ...
user avatar
  • 5,397
5 votes

Naming a method that gets the next enum value or starts from the beginning if the given value is the last

Here is a bit more concise version of your code ...
user avatar
  • 5,560
0 votes

Object-oriented design implementation of an Elevator

To model Elevator better, you may have following two options: Singleton class Elevator which has existence independent of Person. Rename Elevator to ElevatorTrip. This way ElevatorTrip can exist ...
user avatar
1 vote

Json Array to ND Json converter

Parameters It's more natural and flexible to just receive the input and output streams as parameters. The conversion doesn't really care if it's reading the JSON from a file or some other source (e.g. ...
user avatar
  • 2,975
2 votes
Accepted

Json Array to ND Json converter

always increase readability by using access modifiers. Convert is misleading, as you're reading and writing files, so describing the function is very useful to ...
user avatar
  • 4,503
2 votes
Accepted

General web socket client with auto reconnect capabilities

Here are my observations DeribitClient SubscribeToDeribitPriceIndexAsync The re-creation of the ...
user avatar
  • 5,560
2 votes

Json Array to ND Json converter

If sourcePath is null the method would throw an FileNotFoundException as well, because ...
user avatar
  • 49.9k
4 votes
Accepted

C# Language Lexer

Welcome to CR and to C#. First thing first, you should become familiar with C# Naming Conventions. A few that I choose to emphasize in regards to your post: In ...
user avatar
  • 5,532
2 votes

Executing Method Call - C#

You should strive to avoid repeating operations like that. My suggestion would be to test at each stage whether there's more work to do. If we've finished, then return. ...
user avatar
  • 57.8k
1 vote

ReadOnlySpan variant?

The Replace API does not provide a way to specify multiple patterns at the same time. You can try to use Regex Or you can take advantage of the ...
user avatar
  • 5,560
-1 votes

LeetCode: House Robber II C#

Here is another version of a solution ...
user avatar
  • 5,249
1 vote

Saving Multiple Lists to Database - C# Forms

InsertLeg1, InsertLeg2, InsertLeg3 ..etc. I don't see why they're saving a single instance ...
user avatar
  • 4,503
1 vote

Executing Method Call - C#

Why are there InsertLeg<N>Details()s in the first place? Alternative assuming order of execution insignificant, not quite Duff's device: ...
3 votes

Executing Method Call - C#

With reflection you can do something like this ...
user avatar
  • 5,560
1 vote

Saving Multiple Lists to Database - C# Forms

InsertLeg{X} I would suggest to extract the common parts into dedicated methods First let's start with the Collection initilization and Save method call ...
user avatar
  • 5,560
1 vote

Saving Multiple Lists to Database - C# Forms

Quick remarks: Why do you use a stored proc? Why not use an ORM like EntityFramework, or even Dapper? Use descriptive names. leg1 doesn't gain you anything. Don'...
user avatar
  • 10.6k
3 votes
Accepted

ASP.NET Web API for currency

GetCurrencies I would suggest to create a named/typed HttpClient with the proxy handler to make it reusable In this SO topic ...
user avatar
  • 5,560
1 vote
Accepted

Get files from disk filtering by size

Here are my refactoring ideas The if(fileTypes != null) block ...
user avatar
  • 5,560

Top 50 recent answers are included