New answers tagged

1 vote

Method that finds a pair of integers that sum to a specified target

And example of what janos had a description of. I wrote this code before reading all his insights (+1 to him). This will create a Dictionary to store values that have been previous iterated over and ...
  • 4,138
0 votes

Method that finds a pair of integers that sum to a specified target

The "standard" way to optimize for loops is Loop unrolling. However, be aware that compilers often apply such optimization themselves. Another way to ...
1 vote

Method that finds a pair of integers that sum to a specified target

Your question says you want to return a tuple of integers in a list that sum to a specific target sum , but your code actually returns the indices of those numbers rather than the actual numbers. If ...
  • 111
6 votes

Method that finds a pair of integers that sum to a specified target

Optimizing the loop Is there a "standard" way of optimizing for loops? Is there any way to make this particular method faster? A few general ideas to consider off the top of my head, in ...
  • 109k
1 vote

C# Console, Connect 4 Game

Single Level of Abstraction Currently your Main method contains the call to Intro() and then the game loop. It would be easier to understand the code from a high ...
0 votes

Refactoring a binary tree used as a tournament ladder

I'm having a hard time understanding the requirements. I understand what a tournament bracket is, but the teams only get filled in as games are played, so it's not clear what exactly we need to do ...
1 vote

Jet Plane Target Lock On

Performance While it is difficult, or next to impossible, to judge the performance from the code alone, there are some things that are likely to be causing the performance issues you are experiencing. ...
1 vote
Accepted

Finding exceptions and optimisations in weather forecast service

The GetForecastAsync method Since you always call it with DateTime.Now from FetchData.razor ...
  • 5,904
1 vote

Looking to interact with a DbContext entity through a different service

As pointed out in the answer by @BCdotWEB, I fixed the problems in my code and here's a new version with the suggested changes: Changed the TeacherId field in <...
  • 43
3 votes
Accepted

Looking to interact with a DbContext entity through a different service

Some quick remarks: What does "Field" on "Teacher" represent? Moreover, why wouldn't you get the teacher's ID from the user input? Presumably the user selects from a list, what is ...
  • 10.9k
1 vote

Drawing a rectangular playing field

A quick review of your code is that it is very fragile due to all of your magic numbers. Peter Csala addresses this with he suggests using constants. (Forgive me for code below. I am writing this ...
  • 5,677
0 votes

Display a table with exchange rate data

I'm not too familiar with MVC best practices, but I have some general suggestions. First, if (obj.Table != "C") is pretty meaningless to a new reader. ...
4 votes

Drawing a rectangular playing field

Lets do some refactoring exercise together Reduce the number of loops If you look at your for loops' iteration definitions ...
  • 5,904
1 vote
Accepted

Asynchronous tasks to subscribe to orders and fills

Even though you have not explicitly mentioned it in your question but I assume you are using this library. Your SubscribeToAsync is a good starting point. But your ...
  • 5,904
1 vote

EF Core code-first "many-to-many-to-many" (Books with many credits with many people)

With your given model, the BookCreditPersonRelations found on Book would have multiple entries for the same credit, when you have multiple people for that credit. IMO, it's not how you'd give credits ...
0 votes
Accepted

Randomly pick item from list with variable probabilities

The idea is that you have to normalize weighted probability so that they will sum up to 1. Then pick a number betwen [0-1) and then check where the probability selected fall and pick the corresponding ...
  • 228
0 votes

Writing FizzBuzz

Here my proposal, somewhat similar to @euan jones, but use ternary operator to implement "the switch" with old syntax (so no need of boolean, sequence of ternary operators became your ...
  • 228
2 votes

Writing FizzBuzz

One functional approach making use of new c# could look like: ...

Top 50 recent answers are included