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
2
votes
1answer
36 views

What would be proper way to store data from file and validate data from file

what is proper way to save all lines from text file to objects. I have .txt file something like this ...
1
vote
4answers
136 views

C# Code to Find all Divisors of an Integer

I made this so I can feed it integers and return an array with all the divisors of that integer. I put checks in in case the integer is less than 2. Order of integers in the array must be smallest ...
1
vote
2answers
68 views

Chess Model in C# to GetAvailableMoves

Just curious if someone could review my design, and implementation of the following requirements below. I am a mid level dev, and this is for a new job. I am looking for ways to improve, and your ...
2
votes
0answers
48 views

Testable random number generator

Here is a custom Random<T> class which could be used as: ...
2
votes
1answer
25 views

Non-nullable reference type default parameters in C# 8

I was working to upgrade some code to C# 8.0 and came across an interesting pattern with default parameters and non-nullable reference types. I'm working if it's clear enough to the caller. Given ...
0
votes
0answers
18 views

Export csv file using asp.net core web api and react [closed]

I'm intend to create an export function that allow user to export filtered into CSV file. I worked on a sample using the following method ...
0
votes
0answers
51 views

Using objects as tokens instead of enums [closed]

I want to represent the "status" of a thing and use a static representation to refer to it along the code. The best representation for this would be an enum, but I need inheritance, so I came up with ...
2
votes
1answer
22 views

LeetCode: Binary Tree Level Order Traversal C#

Please review for performance. and also naming convention https://leetcode.com/problems/binary-tree-level-order-traversal/ Given a binary tree, return the level order traversal of its nodes' ...
-3
votes
0answers
34 views

Concatenate each line of two textboxes recursively [closed]

I have two textboxes that read from a text file. I want to try to recursively concatenate the two in a way that each value from textbox 1 will get concatenated with EVERY value in textbox 2 separated ...
1
vote
0answers
36 views

What would be a more optimal way of filtering a list into sub-lists

In the start of one of my methods I have a section of code that needs to get three sub-lists of grouped dictionaries from a list of grouped dictionaries. This is a big list and I'm optimizing it a ...
1
vote
1answer
51 views

Designing a dynamic array of Memory Streams

I'm working on a feature for work that requires me to combine a set number of memory streams based on specific conditions. Previous Code Before based on documentation/examples online. In order to ...
3
votes
3answers
65 views

LeetCode: Validate Binary Search Tree C#

I was struggling with this question for many times, and I have solved it every time, because I understand the concept. but I can never get to a good concise solution which is easy to follow. In a ...
4
votes
4answers
112 views

Finding the person with the biggest loss

For a course I following and my code is approved I had to make some code that finds the person with the biggest loss where the input is a string[] The string arrray looks like this : ...
1
vote
0answers
28 views

OpenGL fragment shader optimization questions [closed]

My (simple) game engine has one big fragment shader for the whole scene. Right now, with multiple objects, collision detection and bloom post-processing (4 linear passes) I get frame times of ~18ms ...
1
vote
1answer
34 views

C# MySQL connection and some queries

Goal: I am trying to get the hang of using MySQL connections within C# windows forms. These are such areas I am targeting: Loading dataGridView correctly Refresh dataGridView from an external form (...
1
vote
0answers
60 views

Create and traverse a graph

I have a class with three similar methods. I can't consider which a pattern to use better for refactoring: template method, strategy or something else? I don't know. Can you help me? Update: This code ...
13
votes
5answers
1k views

Group Anagrams (C#)

I am new to C# and would appreciate it if you review my code. This code finds the anagrams in a list of string. Where can I be more efficient in my code? is there any way I can save memory? ...
2
votes
3answers
130 views

Program that outputs the chords in a given key

I am built a program that will give the 7 chords that are found a given major or minor key. My program takes in first a key (C, Ab, F#, etc.) then takes in its mode (Major (input is 'M') and minor (...
0
votes
1answer
90 views

Simple C# logger with multiple implementations

Before I begin showing code, I have two main questions which I feel could help me. What is a service or factory, I've heard of them but why use them? Should I use one shared instance of ILogger ...
3
votes
1answer
50 views

A Brushfire algorithm to generate a distance map in a grid

I'm working on implementing a goal-based pathfinding. first step is to set a goal and calculate the shortest walkable distance between the goal and all points in the grid, using a brushfire algorithm. ...
5
votes
1answer
95 views

Picking a random neighbouring cell, but only picking previously-visited ones if there aren't any unvisited

I'm creating mazes, and have a Cell class (only relevant code shown)... ...
1
vote
0answers
26 views

C# MySQL Database insert list of components

I am writing a function to have insert a list of strings into a MySQL database and C#. The process of creating the list of Components: User has to scan multiple barcodes and have them stored in a ...
-1
votes
0answers
41 views

To display a value in silverlight website based on its database table column values [closed]

I have a database table which has a column named "Status" and the value in the "Status" column will be 1 or 0 or Null. What I am trying to achieve is if the value is 1 it should display "On", If the ...
5
votes
1answer
124 views

Car Showroom Database: Taking user inputs and manipulating arrays

I've been learning C# for around 2 weeks and I'm feeling a bit more confident. I wrote this for general practice and am quite proud but hoping to make it faster and more efficient as I progress and ...
4
votes
0answers
87 views

unsafe bit reading.in parallel

After referencing http://csharpexamples.com/tag/unsafe-bitmap-access/ I tried to put together one for 1 bit per pixel bitmaps. If you can review this, it would help me greatly in verifying this is ...
7
votes
1answer
128 views

WPF BindableProperty<TValue> to Reduce Boiler Plate

I'm sure anyone who has used WPF is familiar with the irritating boilerplate code surrounding properties, usually of this form. ...
2
votes
2answers
146 views

Check for length in a string

I have this logic that seems complicated checking the length and adding a colon. I'd like to see if any of you C# experts can help me simplify it. If the replace remove the full text then I am just ...
1
vote
0answers
87 views

SelectAsync With Max Degree Of Parallelism

I have been looking for the best approach to creating an extension method that would give me the ability to select in a linq query using async/await with a max degree of parallelism. I'm aware that ...
1
vote
1answer
35 views

scan activedirectory for all users and their groups in domain with c# [closed]

I wrote a method for a wpf app in .net core to get all users and their group by name if they are in a group from my active directory domaine. ...
1
vote
1answer
70 views

Serializing object graph to proprietary binary file

I'm creating a class library to read/write .3di files which are binary files describing 3D models for a video game. This review is for the write/serialization process. I've mapped the different ...
4
votes
1answer
58 views

Transforming NodaTime ZoneIntervals

Version 2 may be found here. The company I work for has customers around the globe. I work with a time-series database that contains manufacturing process data for each customer site. I was asked ...
2
votes
1answer
48 views

Open-source C# client for ClickHouse database

I've created an Open-source ADO.NET driver for ClickHouse database: ClickHouse.Client Would appreciate if someone has any hints to improve code quality/performance (or suggest new ideas) The core ...
0
votes
2answers
71 views

How to handle same code parts in Factory Method?

I have classes: ...
8
votes
1answer
89 views

Reversi move checker

I have this method to check if a move is possible in Reversi. The method works as it should, but it doesn't feel right for some reason. It feels very repetitive. I have tried to make it less ...
0
votes
2answers
89 views

Comparing performance between thread, task, parallel

I wrote some function to compare the duration taken for 1000 loops. Just wondering if the comparison is right? For the thread, I want to set to maximum 3 thread. Thread is ...
-2
votes
2answers
81 views

Episode 1: Mastering code and Testing it [closed]

Once upon a time there was a noob developer who learned it all by himself because he grew up in a nation far behind in IT. I've tried to learn C# for about 5 years, without any improvement over the ...
1
vote
3answers
117 views

Can I use IDisposable by treating abstract concepts such as colors as resources?

There are the following class: ...
1
vote
0answers
54 views

My C# code to evaluate order of algorithm is returning logN or N^3 instead of N for simple loop [closed]

As a learning exercise, I am writing a library to evaluate the complexity of an algorithm. I do this by seeing how long the alorgorithm takes for given inputs N, and then do a polynomial regression ...
5
votes
2answers
115 views

Kaprekar's constant algorithm in c#

I have implemented the kaprekar's constant algorithm in c#, and I want your feedback. Here is how the algorithm works: it takes a number of 4 digits (e.g: 5823) we order that number in ascendent ...
2
votes
2answers
97 views

Bitmap in Bitmap (Black & white)

Below is my attempt at bitmap in bitmap searching using 1bpp bitmaps. Any suggestions on how I can reduce complexity and improve speed? Any comment is appreciated. ...
0
votes
1answer
71 views

Console Commands with dependency injection (C#) [closed]

So I'm writing a big server and I've made a simple start on console commands. I'm not sure if the way I'm doing it in is correct so I'd like to have it reviewed. I have a class called ...
2
votes
1answer
101 views

Can this async method be improved or simplified

I was tasked to write process that initially seemed like a straight forward thing. "Fetch data from database, create a cache object, and assign this data to it. Use existing class to model this after."...
2
votes
0answers
47 views

Simple event broker / eventbus in C# (~100 lines of code)

Background I was looking for a simple Event Broker or EventBus (whatever else keyword you can come up with) to use in a small(-...
3
votes
1answer
75 views

Splits up two comma separated items, if they exist

This method splits up two comma separated items, if they exist, and increments the amount if the are already in the list; otherwise add the item to the list I want to know if this code can be ...
2
votes
2answers
93 views

Improving code functionality

I use a change of groupbox locations depending on the number of weeks in the month. Is there any possibility for me to improve the functionality of this code a little bit, is it slow to load on this ...
2
votes
0answers
56 views

Generic search service to filter entries in lists

I'm in the process of implementing a fully generic service to filter out entries (of any type), which are contained in a ICollection. As it is generic, without any ...
2
votes
1answer
65 views

play paper-scissors-rock with the user

I'm new here and also into programming, I've made this small paper-scissors-rock project, and I would like to get it reviewed and know, how can I maybe: simplify my code make it perform better <...
1
vote
1answer
68 views

Add Copyright to PDF File

Will you review the syntax, structure, and logic of my code. It can be tested using the main. ...
6
votes
6answers
3k views

Minimizing string length checker in C# + format(ish) function [closed]

I'm taking on a project from a previous programmer. My goal is to make it a bit smaller and hopefully better. Originally the code has a bunch of length checks and Booleans as shown below. C# ...
1
vote
0answers
70 views

Dependency Injected StackExchange.Redis Client

I am currently building cache for my application, and I would like to have my redis cache client work the same way you would dependency inject a DbContext. I am using StackExchange.Redis to manage my ...

1 2 3 4 5 179