Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [c#]

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

2
votes
0answers
14 views

Compact command line argument parser : Revisited

This question is a follow up to my previous one which can be found here. The user dfhwze suggested me to look into compiler construction and recommended me to write a lexer and a parser that would ...
-3
votes
0answers
19 views

Best way to check if data exists in database using service, Unit of Work and Repository Pattern in c# [on hold]

What is the best way to check if an data exists in the database i am using service, unit of work and repository pattern I don't how check the data in present in database are not ...
1
vote
1answer
70 views

Performance issue with empty lists

Here's my updated version of the problem I posted at Calculating time windows for entities, adding in suggested changes as well as a change I did so that the Reflection is 'cached' in a ...
2
votes
2answers
106 views

Build WHERE clause for search conditions

Here is a set of classes that are used to build where clause for SQL Server and Oracle for different field types e.g. text, <...
1
vote
0answers
17 views

Entity Framework C# updating an entity list generic solution

I have an entity which has a list of other entities in it. for example: class Library { public virtual List<Book> Books{get;set;} } And I would like to ...
1
vote
1answer
32 views

Removing a specific key of ModelState for a specific controller's method

I have a controller for Post and Put request for the same entity: MyModelDTO with some ModelState's attributes. The users can make a ...
5
votes
1answer
94 views

Async concurrency prevention class

Because I'm quite naive regarding C#'s Task Asynchronous Programming and concurrency in general, and because it's so difficult to test, I'm concerned about the safety of this code. It's likely that ...
5
votes
1answer
166 views

Scraping an parsing jockeys data using Task.Run

I started to have HUGE doubts regarding my code and I need some advice from more experienced programmers and architects. On the button click, the application runs a method, that is running a ...
2
votes
1answer
55 views

Compact command line argument parser

So, I decided to write my own little command line argument parser for various other projects I work on. I am aware that there are many good command line parser libraries, but I did wrote my own anyway ...
1
vote
1answer
39 views

Rotate matrix clockWise and counter clockWise

This code is a mix of the same question one time rotating to the right and one time to the left. I tried to simplify the code since I'm struggling with all of the indexing here. https://leetcode.com/...
3
votes
1answer
43 views

CareerCup (Bloomberg): Check if string is valid based on brackets

The goal of this problem is to determine if a string with brackets is valid. Below is a summary of the question from careercup. Check if string s is valid based on brackets ...
3
votes
1answer
70 views

Parsing Game Entities

Could use some help with my presentation in Software Development. I'm presenting how I reworked a game's parser (SpaceTaxi). Basically we take in a .txt file with ASCII characters and convert them ...
4
votes
2answers
192 views

Object-oriented design implementation of an Elevator

I am a newbie when it comes to Object Oriented Programming and I have read a lot of online articles and lessons so I want to try it out on my own. I've written a console app in C# and tried ...
-2
votes
0answers
39 views

How's my SceneManager? [on hold]

0 I looked up a few tutorials and made my own from a mish-mash of them. I ask because, I tend to find out that there's a far better was that won't come back to bite me later on. What I do is store ...
3
votes
0answers
39 views

msmq bulk send in c# [on hold]

Please review the code below and provide constructive feedback to improve. Multiple threads call the SendMessageToMSMQ method to send messages to a msmq queue. ...
2
votes
1answer
56 views

Should I re-throw exceptions within a method, or is there a better way to handle it? [on hold]

When handling errors in C#, is it acceptable/appropriate to re-throw exceptions that are caught in a try/catch? My scenario is that I am making an HTTP request and ...
5
votes
0answers
45 views

SQS subscriber pattern in background service

I have the below code to pull messages from a FIFO SQS queue. Using the while (IsRunning) loop makes me feel to question the code design. Is there a pattern I am ...
4
votes
1answer
43 views

LeetCode: Intersection of two arrays ii C#

https://leetcode.com/problems/intersection-of-two-arrays-ii/ Please review for performance, I am having a problem with using TryGetValue, if someone can explain how this can be used in here. Given ...
3
votes
0answers
40 views

LeetCode: Best Time to Buy and Sell Stock II C#

https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ Please review for performance. Say you have an array for which the ith element is the price of a given stock on day i. ...
2
votes
0answers
28 views

LeetCode: Remove Duplicates from Sorted Array

Please review for performance https://leetcode.com/explore/featured/card/top-interview-questions-easy/92/array/727/ Given a sorted array nums, remove the duplicates in-place such that each ...
-2
votes
0answers
33 views

Assigning variable value: check if not equal necessary? [closed]

Consider the following code: ...
6
votes
1answer
142 views

Enumerate all members and types with specific attributes

I have a use-case where I need to retrieve all members with specific attributes in the class and interface hierarchy - I usually need the first match and apply its rules to child members. The built-in ...
2
votes
1answer
53 views

Deserializing response to correct type

I use this method to get either Customer or Account. The server will determine which type it is. The response will have a property "Type": "Customer" or ...
1
vote
2answers
89 views

Object-oriented implementation on Expense Tracking App [on hold]

I am creating a Expense Tracking Application in C# and right now I am trying to build its building blocks in a console app. I Would like to know your feedback if it is in a Object Oriented Design/...
1
vote
0answers
31 views

Tightly coupled Basic Authentication Filter

I have an asp.net web api and I would like to use basic authentication. Is there any way to make this loosely coupled? I tried constructor DI but I couldn't figure it out how to pass Dbcontext into ...
3
votes
1answer
47 views

LeetCode: Transpose Matrix C#

Please review performance https://leetcode.com/problems/transpose-matrix/ Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped over it's main ...
1
vote
0answers
92 views

LeetCode: trapping rain water C#

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. The above elevation map is represented by array [...
6
votes
3answers
297 views

Calculating time windows for entities

I have made some code that operates on multiple entities and creates 'time windows' for them. Basically, the entities will contain states, usually in boolean or int. They will be timestamped and in ...
2
votes
1answer
51 views

Static Methods for Dealing with Conversions from and to UTC

I asked this question over at stackoverflow but was told it may be better suited here. So I absolutely want to store DateTimeOffset objects in UTC format. To ...
0
votes
0answers
25 views

WebApiConfig Register Dbcontext usage [closed]

I am trying to implement basic authentication. I am using asp.net web API and EF code first approach. Here is the class I am trying to query the DB table. ...
2
votes
1answer
72 views

Periodically sending data from database to an API

I'm trying to make a timed background service in .NET Core (I found this approach in Microsoft Docs), that every 15 seconds it gets data from the database (1000 rows max, if something exists) then ...
0
votes
0answers
27 views

Business logic refactoring needed

I am using asp.net web API and EF code first. I am querying the database based on values inside of the request object (initiate). If there are results, I am updating the database. Then I am querying ...
4
votes
1answer
80 views

How to group custom events [closed]

I have a number of custom events that a class might or might not subscribe to. ...
2
votes
0answers
34 views

Retrieve file and other input fields from JavaScript to send to ASP.NET Core

I am currently developing an e-commerce website where users can upload their photos to customise their products. The use case begins when the user selects a product from our website (e.g. shirt). ...
3
votes
1answer
53 views

Logic is stored in Components that receive input data and update output data via Observables

I have C# ASP.Net Core Webapi application that makes some calculations for physical models. I have this project class: ...
0
votes
0answers
40 views

My first c# program: Get Data from Sql Server and show it in Textboxes

So I have been programming in VB.net and want to learn C#. I "successfully" created a simple program that retrieves data from Sql Server during Form1_Load. The ...
5
votes
1answer
52 views

Rate limiting variable-duration operations over a time interval

I want a rate-limiter that permits, at most, N operations over T seconds. I found a sample implementation here but it makes an assumption that operations complete in a predictable, consistent amount ...
5
votes
2answers
80 views

HttpClient reusable instance for simple calls on another methods

I wrote a HttpClient instantiable class that will be used as reference to simplify API calls in other methods inside other classes, so the user could call it in a ...
1
vote
1answer
59 views

A ValueService is used to share data among objects

I have C# code that makes some calculations for physical models. I have this project class: ...
1
vote
1answer
34 views

Inter module communication

I have two modules, Notification which basically contains SignalR hubs and CoreSetup which contains core setup logic in it. I have a class in CoreSetup module which keeps track of employee location . ...
2
votes
2answers
87 views
7
votes
1answer
132 views

Drone Delivery Scheduling Service

I recently did a interview with WalmartLabs. I was tasked with a take home assignment. I didn't sign a NDA and a team at WalmartLabs said I could post the code on GitHub. I was tasked with developing ...
3
votes
1answer
70 views

Get result from form website operation

I want to get a result from the website when I submit a form. There are several things that can go wrong. In a simple scenario I want to return: true - when ...
1
vote
0answers
60 views

C# Generic Repository and Unit of Work Implementation for Northwind [closed]

I have created 3 projects to implement layered architecture design mainly the - Presentation Layer (Web) - Domain Model Layer - Infrastructure Layer For simplicity, I have only two domain model ...
3
votes
1answer
66 views

Get all children recursively in Entity Framework Core

In Entity Framework Core we can have recursive entities. But we cannot do an "Include" for these recursives (can we?). So I wrote a Get-method that does it for me: ...
3
votes
1answer
42 views

Initializing entity framework context in constructor

We use the architecture shown in the code below to initialize the DB context for our MVC 5 project using entity framework 6 We have the following questions related to it: Is it safe to initialize ...
2
votes
1answer
66 views

Exception, errors handling, best practice in WebApi Core

I'm making my WebApi project. My logic is, the controller didn't see data. It only triggers a service that returns objects to it. My simple method from ...
2
votes
1answer
48 views

Populating dropdown lists, using SQL vs. using expression trees and reflection

I'm working with a large enterprise SQL Server database with dozens of tables that are used mainly as lookups to populate dropdown lists, etc. These tables all follow the convention of having (table)...
7
votes
2answers
178 views

LeetCode: last stone weight C#

https://leetcode.com/problems/last-stone-weight/ We have a collection of rocks, each rock has a positive integer weight. Each turn, we choose the two heaviest rocks and smash them together. ...
7
votes
4answers
485 views

Making an Action<T> event also usable as Action<object> and Action in C#

Edit I've added a second pass at this problem based on the answers that have been posted by other users so far: https://codereview.stackexchange.com/a/221525/75659 Context Before presenting the ...