Questions tagged [c#]

C# is a multi-paradigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform. Use this tag for questions related to C#. In case a specific version of the framework is used, you could also include that tag; for instance .net-2.0.

Filter by
Sorted by
Tagged with
0
votes
2answers
14 views

Validating CSV headers against an expected list

My application (legacy code) reads a CSV input file with an expected format with regards to Column names as follows: 1st column - Should say "Marker" 2nd column - Should say "Category" 3rd column ... ...
0
votes
0answers
9 views

C# Simplify the code for Calculation of the Bowling Game score

I am a new in developer role, and I have my code which I wouldlike to simplify or make it better. And wondering if someone can do a quick check. The code calculates the Score of the Bowling game, ...
-4
votes
0answers
28 views

Getting equals function working for a C# calculator [closed]

So I was tasked with making a GUI calculator in C# (without using any data structures like a stack) that allows the user to enter in an expression but I am having trouble getting the equals function ...
2
votes
1answer
27 views

Deconstruct tuple and store each element into a List of their respective element type

I encountered a use case where it was needed to store each element of a tuple into a list of their respective type of the tuple element. To streamline this feature I wrote a method extension that I ...
1
vote
0answers
17 views

Feedback on reactive operator for distinct values that must change by amount

I would like feedback on this DistinctUntilChangedBy operator for System.Reactive that only emit when the current value is ...
0
votes
1answer
47 views

To convert all the class properties to IDictionary<string, dynamic>

I have the requirement to return the result of my ViewModel as a Dictionary of KeyValue pairs. My view model comprises of multiple classes and can have null values in properties. I need to return only ...
2
votes
2answers
42 views

Get resulting rectangle from two overlapping rectangles

I have a function that creates a rectangle from two rectangles that overlap, i was wondering if there is a smarter way to do it purely mathematically rather than lots of if statements to check min and ...
-2
votes
1answer
78 views

How to get rid of many if null checks - c# [closed]

How could I refactor this code to get it more cleaner: ...
1
vote
1answer
76 views

Generate Unique ID in C#

Objective To create a unique id with few characters as possible. Language: C# Engine Unity3D Target : iOS && iPadOS Scenario I found quite a few solutions from Stack Exchange but would ...
2
votes
0answers
55 views

Execute asynchronous read in parallel

I found it useful to execute multiple reads in parallel using a set of my extension methods for TaskFactory, which could be used as: ...
1
vote
1answer
21 views

Extension method for getting custom Principal Claim

I'm writing extension methods to shorten the code required to get custom Claims from an IPrincipal. I have two general forms for ...
1
vote
2answers
55 views

Generic Implementation for Paging Class in c#

I have created one generic Page class for store paging information with its data. The class look like: ...
1
vote
2answers
116 views

Calculating a page size to execute a subset of jobs at a time

We have to execute a bunch of jobs , each have an ID and they are passed on to the processor . Since the processor can only work on a limited number of jobs (denoted by ...
4
votes
1answer
94 views

Testable REST API Client

GitHub and NuGet Allows to invoke public/private REST API just by defining an interface. 200 lines of C# in total. Demo Sample API is publicly available at http://jsonplaceholder.typicode.com: <...
3
votes
0answers
62 views

Prime Number Table, i.e. List<int>

I have written many variations of the Sieve of Eratosthenses, which is the fastest way to generate a large collection of primes. If you later want to query the gathered primes by count or at a ...
5
votes
1answer
49 views

Strictly typed dynamic proxy to call dynamic object

GitHub and NuGet I would like to use DynamicObject derived types to execute REST API/NodeJS module calls. It would also help to capture API shape in a strictly typed manner, so here comes an ...
-2
votes
0answers
22 views

I would like to add the outcome of a random number generator to a list using c# [closed]

I want to add the 10 random numbers created by this code to a list but how can i do this if i don't know the values of these numbers? ...
0
votes
0answers
33 views

Ternary Expression To Binary Tree [closed]

This is my tried version in C# for this question- TernaryExpression To Binary ...
4
votes
0answers
67 views

Production planner

I have a class that creates an object, PlannedYear, and then passes that object into several other classes to manipulate it. The ultimate goal of the class is to ...
-1
votes
0answers
56 views

Making A C# Console text Adventure [closed]

(all the current code in my project works so far) ok so here it goes for an assignment im having to work on whilst learning C#, we were told we had to make a console based application. i chose to ...
0
votes
0answers
63 views

Cancel Long Running Query using Cancellation Token AND SqlCommand.Cancel()

I need to be able to cancel a long running query programmatically through our application. The code below will kick off a long running query and give control back to the main thread. At any ...
1
vote
0answers
27 views

Next Bigger Number with the same digits Solution [closed]

Please review my code. I would love to know what improvements I can make in terms of efficiency as well as readability. Thank you! ...
6
votes
1answer
136 views

Minesweeper Implementation c# winforms

I made a minesweeper game in c# as a method of studying, and right now its fully operational. I tried to use inheritance, recursion, and other fundamentals as clean as possible. Also I tried to use ...
5
votes
2answers
125 views

Network IP packet tracker

this is my code for watching IP packets. I am doing project for my self because I want to learn how this things works. This is my IP Packet class: ...
-2
votes
0answers
36 views

Re-fetching revoked OAuth token

I am trying to handle the case if a OAuth V1 token is expired or revoked and has to be re-fetched and wonder if I'm doing it right. ...
-2
votes
1answer
78 views

Make foreach with nested-if's more compact and readable [closed]

Code works fine. What I'm looking for is C# syntax to make the foreach loop below more elegant, compact and readable. The foreach with the multiple if's takes up ...
1
vote
0answers
72 views

C# trading indicators calculation

I have a stream of stock prices and I want to design indicators calculation for them. Indicator can be imagined as an additional chart displayed next to the prices chart. More specifically, it is ...
4
votes
0answers
86 views

WPF/C# - Rock, Paper, Scissors Game

I have made my first little project using C#/WPF - a simple rock, paper, scissors game. I am happy with the functionality and look but I would love to know how a more experienced programmer would ...
2
votes
0answers
23 views

Manage independent script component architecture in unity

I have different set of objects where I have to show Name UI and Menu UI using OnMouseDown and on OnMouseEnter. Remember Both ...
4
votes
1answer
93 views

Mapping Excel rows to model

I have an Excel file and each row within the sheet represents an employee's data. I am trying to find a cleaner way to map each row to a model object: ...
3
votes
2answers
95 views

Validate if either or both of two fields has been provided, as a ValidationAttribute

I have a binding model where at least one of two fields must be specified. I can't just set them both as [Required]. Here is what I came up with: ...
3
votes
1answer
73 views

Iterate through Expression Tree

I'm trying to build an iterator (enumerator) that can select specific elements in an Expression tree by traversing the tree and deferring further iteration until ...
5
votes
1answer
85 views

RPG Parser routine

I wanted a routine that would allow me to use the NumPad keys for directional commands. 1-9 for each compass point, - for up and + for down. If one of these keys are not pressed, it would act as a ...
2
votes
0answers
51 views

Generating Infinite Procedural Terrain Using Command-Line Graphics

Continuing my trend of (ab)using the Windows command-line interface to do fancy graphics-related things with my command-line-graphics library, CLIGL, I've created an infinite procedural terrain ...
2
votes
1answer
94 views

Strictly typed JSON representation

I would like to be specific in parameter types or write something like this: Test test = (Json<Test>)"{\"age\": 46}"; Where: ...
-1
votes
1answer
101 views

Naming convention when converting between types? [closed]

If I have a method where the input is a list of integers, and within that method I convert the list to a list of strings, what is the best way to name the new list? For example (using ...
5
votes
0answers
75 views

Using ClientFactory-pattern with Dependency Injection

I initially posted this on Stackoverflow but was recommended to try here instead. I'm looking for feedback on why the implementation of my ClientFactory is probably bad, from a Dependency ...
3
votes
1answer
70 views

Refactoring code to implement clean code using repositories

I've been refactoring code today, try to implement a clean code setup using repositories. Is this on track? Can any improvements be made? ...
7
votes
2answers
320 views

Chaining statistics in a dice queue

I've previously came up with the question "Rolling dice in a method chain" and was interested if this could be improved. It could, so now I have this class: ...
7
votes
3answers
439 views

Averaging quaternions

To compensate for shaky hands when holding a mobile device I'm averaging the rotation of the phone over the last n (in this case 16) frames, and setting the camera'...
0
votes
1answer
59 views

Mixing Async and Sync in same HTTP request ASP.NET Core C#

Is it bad practice to mix async and sync call in same ASP.NET core API call? For example, in following code method CropBlackBroderOfAnImageAsync is an async method....
4
votes
0answers
30 views

WPF Custom Control with a Single ObservableCollection DependencyProperty

I'm learning how to write WPF custom controls. My example, NameLister, exposes a single DependencyProperty, Names, of type ...
2
votes
0answers
51 views

Unit testing the code that is written using repository pattern

I have implemented my business logic using the repository pattern. I have an Approve method in my controller. I am calling the service method ...
4
votes
2answers
137 views

Is there a way to avoid repetitive code in the following switch statement?

I have the following method, which is called every time the user clicks a checkbox within a Datagrid. Each column within this ...
2
votes
1answer
51 views

String template using concrete implementation instead of external library

Q1: What are the benefits of using any external library e.g Antlr3.StringTemplate? Q2: What are the potential issues with the below implementation? ...
8
votes
3answers
725 views

Rolling dice in a method chain

I've been writing code for nearly 40 years now and am still not too old to learn and understand new things. Right now, my focus is a bit of OO with functional programming combined and C# with Linq is ...
3
votes
2answers
174 views

A prime numbers enumeration optimized for speed

I know there is this thing called "Eratosthenes" but that requires the allocation of a large array while I want to find (small) prime numbers fast, yet without needing too much memory. So I wrote ...
17
votes
6answers
6k views

Solving Fizz Buzz using LINQ in C#

The Fizz Buzz challenge is well-known and should not need any explanations, right? I recently got a bit bored and came up with a solution for Fizz Buzz using LINQ and even asynchronous code and a lot ...
6
votes
2answers
135 views

Find the largest sum of any slice inside an array

This is the 26th exercise I solved from Codility. It scores 100%. I think I improved a lot since I started with this lessons, around 2 months ago, but still every post I made had things to be improved....
3
votes
3answers
79 views

Method for rotating [Flags] Enums

I'm working on a method to rotate System.Enum values that have the [System.Flag] attribute set. I've tried to think of cases ...