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.

-3
votes
0answers
22 views

What is the best way to order the parameters in the action methods in asp.net web api? [on hold]

In our application, We are injecting the [FromServices] directly into the action method along with [FromBody], and now it ...
0
votes
0answers
28 views

Wpf background task using thread

In my app I need to verify several records and the operation takes time, so I decided to use threads in order to keep the UI responsive. This is the code: ...
1
vote
3answers
73 views

Alternative for two sequentially executed loops with identical ranges [on hold]

For the moment I'm executing my code as follows: foreach (int data in dataList) { PreProcess(data); } foreach (int data in dataList) { Process(data); } ...
2
votes
1answer
82 views

TicTacToe endgame feedback in C#

I'm learning C# and currently having an assignment on Tic Tac Toe. I'd love to have some feedback on where I can improve. I've managed to create the end game functions but I feel it could be improved....
0
votes
1answer
73 views

Which approach is better: Inject fake API call object OR fake the result? [on hold]

I am working on a Unit Test where I call an API and get a XML as a result. This API call is done by a downloader class that gets a URL in the constructor. Now I have a dilemma. What should I do, fake ...
4
votes
1answer
166 views

Algorithm to find the number of years, months, days, etc between two dates

I've been working on this one for a while. Took me a while to figure out all the logic rules for dates and months. The goal of this method is to return the number of years, months, days, hours, ...
0
votes
0answers
30 views

Optimize TreeView method

I have very large method who insert child of TreeView, basically I do two different querys and set little changes I.E. firs foreach insert first child of parent ...
4
votes
1answer
69 views

Simple calculator in C# WPF

I'm beginning to learn WPF and wanted to do a quick exercise. The code is as simple as it gets but I tried to evaluate each and every possible edge case. Any improvement is welcome, thanks. C#: <...
-1
votes
0answers
21 views

How to unit test business service methods using nunit and moq [on hold]

As i am new to moq and Nunit, i dont know how to unit test the business service. I have the business service called studentdetailsbs.cs,i need to test whether fetchallstudents returns studentlist or ...
5
votes
1answer
162 views
+50

Graph puzzle resolver

I've solved test task for job vacancy. Need your feedback about my solution. Task The image below shows the puzzle in the solved state. The puzzle consists of 10 cells. Among the cells one is empty, ...
0
votes
0answers
14 views

Mini HttpClient json post by Action parameter

This is an implementation of HttpClient Json Post by Action parameter. Logic: It is mainly convenient to pass the url and object (automatically converted to json by Json.Net), and can use ...
1
vote
0answers
48 views

C# Async/Await networking server

I made a simple async networking server and I'd like to get some input on the code, whether things can be done better and whether the code is stable (able to hold more than 1000 connections without ...
-2
votes
0answers
16 views

readbinary in datagrid view [closed]

Need to do the reading in the datagridview The model did, but I can not figure out how to make it appear in datagridview Model: ...
1
vote
1answer
38 views

CustomerIdentity class to bridge gap between internal and external CustomerIDs

Purpose This was designed to be able to seamlessly replace string SAPCustomerID and int CustomerID in parameter lists with <...
4
votes
2answers
67 views

Simple person manager console-app

The code below is for a coding challenge for a job. I have everything working as they requested, I've reviewed it myself and believe everything is good. I'm just looking to see if anyone see's ...
1
vote
1answer
37 views

Making EmployeeHistory ViewModel immutable as code analysis suggested

I want to display on a view the EmployeeHistory view model sorted by elements.assignEffDateNext and I want to instantiate and ...
8
votes
3answers
564 views

XML node removal method with 5 arguments

I read somewhere that you should try to have as few method arguments as possible to make code easier to read, understand and use. I agree with this to a point but I'm not sure how I can make the ...
1
vote
1answer
54 views

Encrypt data to be send from service to service

I'm working with another company in a new application for my company. My job right now is to send on demand to the other company the data that they need, ciphering some of it. I should point out that ...
-2
votes
0answers
30 views

I'm trying to make a collection class in C# [closed]

As a side project i'm trying to remake one of my favorite games from the old days, moria/angband. I'm doing it from scratch and in C#. In order to store the inventory I have the following classes, ...
1
vote
0answers
53 views

Async SelectMany implementation

Async SelectMany takes an enumeration (length unknown) of tasks, each of which returns another enumeration (length unknown and likely different from one another), and returns results from the second ...
1
vote
0answers
21 views

Industrial Automation App with tightly integrated classes

I have written a Windows Forms app that interfaces with a variety of equipment to automate the testing of some gas sensors. The program has four main objects, and sometimes these objects have to call ...
1
vote
0answers
53 views

Extension “With” for immutable types

(My code is basically a rewrite of https://github.com/ababik/Remute so much of the credit goes there) The idea is to use lambda expression to provide a general With...
2
votes
1answer
48 views

Query builder with OOP design

I am designing a query builder, where the user can just add conditions or groups, and each group can, in turn, have conditions in it. I came up wit the below class design. Can this design be improved? ...
-1
votes
0answers
33 views

Control Application Insight Logging

I used TelemetryClient to synchronize my application logs in Azure Application Insight. Now I want to control my logging according to the environment. I tried to ...
-2
votes
0answers
19 views

BinaryReader unicode error [closed]

I'm trying to sort out the binaryReader in an error Unable to read after finishing the file I can not understand what the error is and why he does not read Unicode ...
3
votes
0answers
56 views

TCP client reading socket asynchronously

I'm relatively new to .Net/UWP networking and have been trying to make sense of the APIs. I'd like to implement a TCP client that is capable of reading and sending messages independently (there is no ...
-1
votes
0answers
23 views

Updated quiz code, how to imlement C# OOP classes to accomplish the same thing [closed]

I asked for help on a C# Quiz program I am writing for my ENGR115 class in this thread: Original Question Roland replied with some good advice for me, which I followed, and came up with this revised ...
1
vote
0answers
20 views

Transparent proxy using HttpClient

I'm looking for feedback on some code I've written to work as a transparent proxy. I'm developing a web app that needs information from another web site's API, but that web site has disabled CORS and ...
2
votes
1answer
50 views

Revision: BinaryTree<T> written in C#

Since my last question (BinaryTree<T> written in C#), I have rewritten my code based on the responses. My project can be found on my GitHub repo here; ...
-2
votes
0answers
40 views

Im teaching c# arrays is this a good tutorial? [migrated]

So I am jumping in for a teacher next week and my job is to teach them about arrays in c#. They know variables, int, string, double and how to output data. I tried to build this so it would be ...
5
votes
1answer
79 views

Building a bool expressions validator

I'm writing a system that's responsible for changing Status of Order. There's a specific set of rules that define route of changing ...
-1
votes
0answers
19 views

Entity Framework Core - Dynamic Relationship Builder [closed]

So I have a relatively large database that is defined with code first principles in Entity Framework Core. I had quite a few lines of relationships within my context file. So I went ahead and wrote a ...
0
votes
1answer
57 views

Checking For multiple null references [closed]

So this question might be a bit opinion based but I am a bit confused, say i have these two code snippets - ...
-1
votes
0answers
32 views

is there a better way to test this class? [closed]

Recently, I am learning unit test and try to use this skill in my project. However, I have some question about how to test following code. ...
1
vote
0answers
28 views

Helper class for ASP.net to return data from SQL server

My goal is to create a class that I can call from my webpages like this. Similar to a data access layer? ...
2
votes
1answer
62 views

AVL height-balanced binary search Tree and Dictionary

Mostly as a learning exercise, and partly as I thought it might be useful, I have written an implementation of AVL trees ( https://en.wikipedia.org/wiki/AVL_tree ). An AVL tree is a height-balanced ...
0
votes
0answers
22 views

WPF Async Filter [closed]

I'm using a SearchWaterMArkTextBox and a Gridview, where I've bind this line to my gridview. ...
11
votes
2answers
2k views

BinaryTree<T> written in C#

I've written a binary-tree using .NET Core 3.0. What can I do to improve my coding style? ...
0
votes
0answers
16 views

Extension to BindingList<T> that allows for cancelable notifications of changing and deleting

This is an extension of the System.ComponentModel.BindingList<T> class that allows for notifications of item changing and deleting. These notifications ...
2
votes
1answer
63 views

Write a function that adds two numbers stored in a linked list and returns the sum

Just for fun I did the following exercise from "Cracking the coding interview. 4th edition": You have two numbers represented by a linked list, where each node contains a single digit. The digits ...
2
votes
1answer
40 views

Upload a file asynchronously

I need your opinion about my practice. I want to improve it. The requirements are the following: RESTFUL + OWIN (SelfHosted) Endpoint - Upload a file asynchronously Make a request to the endpoint ...
4
votes
2answers
75 views

Switch-Case pattern for non-constant types (part 2)

You can find the "part 1" here. 1. Objectives The main goal of this post is to build a switch-like structure, which allows to use non-constant Type (e.g. Type, <...
4
votes
1answer
113 views

Quiz program that asks 10 questions, repeats incorrectly answered ones a second time, gives results at end

I'm currently attending ERAU (online), and in my Computing for Engineers class we are learning C#. An ongoing project throughout the class is to build a "quiz" program that asks 10 questions, in order,...
0
votes
0answers
53 views

Aggregate sensor readings from multiple sources

I've developed a toy example to investigate how async works in C#. Though I've learned a lot this week, I'm still unsure of the finer details, as this is my first C#...
2
votes
1answer
93 views

Safely Initialising a static variable to a file [closed]

This might appear to be a trivial task, but I think it's not the case. My code originally looked like this: ...
0
votes
2answers
116 views

Switch-Case pattern for non-constant types [closed]

Edit: Following answers, I modified my code, and wrote an other question. History Recently, I (stupidly) tried to make a switch on myObj.GetType(). Of course, it ...
0
votes
1answer
46 views

Enforcing C# Task to exist only once at any given point of time for a given ID

There were multiple times in different applications that I needed to accomplish the following behavior with C# Task and I did it in a certain way, and would like to ...
15
votes
3answers
277 views

Traversing an infinite graph using Dijkstra's algorithm to maximize cookie production speed

Imagine the following situation: It is the year 20XX. You are a prodigious baker, capable of baking cookies at an astonishing rate of 1 cookie per second. Your archnemesis, an equally excellent baker,...
3
votes
0answers
27 views

Generic object-to-XML mapper

This code is part of a larger mapping library I'm working on to address some business concerns of transforming data. I was inspired by mapstruct in Java, but opted for users to annotate / add ...
6
votes
1answer
516 views

TCP client and server API

Hello I made a server and client API for TCP connection. It is intended to shorten the work you need to do to prepare the server and client. It's separeted in 3 projects - ...