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
0answers
2 views

Design pattern to replace switch case?

I have a simple service class here which import csv or xml file into database using .NET Standard library C#. Any comments? ...
6
votes
2answers
1k views

Tic-Tac-Toe code using c#

I am a beginner coder and was wondering how to improve my c# console code. It makes a tic-tac-toe game. ...
2
votes
2answers
125 views

Dependency Inversion Principle with connection to a SQL Server

First, this is my first post on this stack exchange site. So please be patient with me. If there is something wrong or you miss something, please let me know. I will add it asap. I am currently ...
-1
votes
0answers
27 views

Asp.net Rest Api higher requests

I would like to build a Asp.net (with net5) rest api service, and i would like to know if i'm on right way. This service will cache values from other service Y for X minutes, if client will ask data ...
-1
votes
0answers
17 views

C# Winforms App ,EF6, DB First with Auto Mapper Generic Repository and UOW context is not updated automatically when database is changed externally [closed]

I've started to work on a single user c# winforms application, with EF6 db first approach, AutoMapper, Generic Repository and UnitOfWork. They have been previously implemented by others former ...
1
vote
0answers
38 views

Is repository pattern violated while using IQueryable outside of it?

I am writting an API backend application using .NET Core and Visual Studio. Here is the solution structure: [ProjectName] - Solution ...
-4
votes
0answers
10 views

Add git sub-module in a repo using LibGit2sharp [closed]

I'm working with a local Git repository in some .NET code using the open source library used by the Visual Studio Tools for Git, LibGit2Sharp. I need to create some submodules. The code I used was: <...
0
votes
0answers
62 views

Grade Book project

I started to learn C# recently by following the official Microsoft docs. I originally created the GradeBook project from Pluralsight which I am now adding my own features to. This section lets the ...
0
votes
0answers
56 views

Is there a way to optimize this graphics/bitmap drawing code in C#?

I am not doing anything fancy so not sure if there are any tricks to make it faster. It's a progress bar where I draw some numeric text on top. I only draw 1 pixel height image and then resize it. But ...
-3
votes
0answers
18 views

Parsing DateTime with timezone [closed]

I am facing difficulty in parsing a DateTime with the structure of time zone: I am trying to parse it this way: ...
0
votes
1answer
67 views

C# code for Dhond't voting method UK Parliament

Please can you check if the code I have written follows 4 rules of OOP well enough, if there is anything that could be improved or is just wrong I am happy to change (very new to C# sorry if it's ...
2
votes
0answers
68 views

Split a list of points into a list of lines in C#

I have a list of points (System.Drawing.Point) obtained from an edge finder function that scanned a bitmap for objects. Each point is guaranteed to be a part of an ...
2
votes
3answers
242 views

ArrayDowncasters Implementation for Downcasting from System.Array to Array of Specific Type in C#

I am working with System.Array and I am trying to convert System.Array objects to array of specific type (such as ...
-1
votes
0answers
52 views

How to use Dependency Injection properly in asp.net core?

I have a legacy Asp.net Core 3.1 application which uses Kestrel server and all our GET and <...
1
vote
1answer
46 views

C# asynchronous tasks training (turn-based simulation)

I know embarassingly little about asynchronous programming in C#, so decided to start catching up. It would help me a lot if anyone checked this basic example I've created. Assumption: we're creating ...
6
votes
2answers
664 views

C# - Linq - Techniques for avoiding repeating same pieces of code

I am writing a piece of code for C# Web Api, letting the clients to pass a column name and sort direction as parameter. Although there are, like, 30-ish properties, so the following code (despite it ...
1
vote
1answer
108 views

Eliminating repetitions of subsequent items in a list

I would like to convert a list A A = {1, 12, 3, 3, 3, 8, 5, 5 } into list B ...
0
votes
0answers
80 views

Is the right usecase implemenation of ValueTask and Task in C#

I am trying to understand the right usage of Task vs ValueTask in .NetCore2.0(+) or C# 7.0(+) Task - Is a class/object types & uses heap memory should be used in async method when the operation ...
0
votes
1answer
103 views

Is this correct way to setup DB Infrastructure with repository pattern and Dapper

So, I am using Repository pattern with Dapper and ADO.NET. I have my based DB infrastructure setup as follows: ...
2
votes
1answer
60 views

Generate a bar chart of weekly data from SQLite.NET

I am using Xamarin.Forms, Microcharts and SQLite.NET to create a mobile app. The SQLite.NET database stores details about books (book ID and entry date - the date it was entered in the system). The ...
2
votes
0answers
123 views

Tic Tac Toe game using WPF+MVVM

I am looking for some advice on how to create a new ViewModel within an already existing ViewModel. I am creating a Tic Tac Toe game, to improve my knowledge of the MVVM pattern, WPF and C#. I am ...
2
votes
2answers
157 views

Getting metadata from MusicBrainz service

I've written a program which does the following things: calls third-party utility to get mp3 file fingerprint asks MusicBrainz IDs from AcoustID service asks metadata from MusicBrainz for each ID I'...
2
votes
0answers
76 views

Read compressed XML file inside ZIP and parse data as fast as possible

I am trying to read and parse an XML file inside of a ZIP archive as fast as possible. The XML file is roughly 85GB in size, so I know for a fact that I/O also plays a role here, as I need to ...
1
vote
0answers
90 views

A Generic Two Dimensional Data Plane with Common Math Calculation Build-in Methods in C#

This is a follow-up question for A Generic Two Dimensional Data Plane with SubPlane Method in C#. Thanks to aepot's answer. I am trying to implement a series methods to enhance the ability and ...
2
votes
1answer
65 views

Making DataTable results more readable

I have the method below, which generates backtesting results. However, it's highly unreadable. What could you possibly suggest to me in order to make it more readable? ...
1
vote
1answer
85 views

ConvertAll Methods Implementation for Jagged Arrays in C#

This is a follow-up question for ConvertAll Methods Implementation for Multidimensional Array in C# and ConvertAll Methods Implementation for Multidimensional Array in C# - follow-up. Besides the ...
0
votes
0answers
34 views

Resetable async Observable subscription that won't naturally dispose itself

I wanted to have a code review on the following Observable implementation, because there are many opinions and this one might not be the most efficient one. I would like to hear yours thoughts. What I ...
2
votes
1answer
64 views

Reducing Inventory Quantity When Order Is Being Processed

I've got a method which removes quantity from inventory when an order is completed. If there is not enough inventory quantity available, the order completion fails and the sql transaction is rolled ...
1
vote
2answers
60 views

Store, retrieve and delete settings in C# Registry

My code writes, reads, and removes program settings in the registry. I'm using Visual Studio 2019 and my target Framework is .NET Framework 4.8. I'm looking for more elegant functions. Is there error ...
1
vote
1answer
66 views

ConvertAll Methods Implementation for Multidimensional Array in C# - follow-up

This is a follow-up question for ConvertAll Methods Implementation for Multidimensional Array in C#. Thanks to aepot's answer and Olivier's answer. In order to match the usage of the build-in API <...
0
votes
1answer
83 views

Big Sorting - Performant Sorting

Consider an array of numeric strings where each string is a positive whole number. Sort the array's string elements in ascending order of their numeric values, and return the sorted array. Return: ...
-2
votes
1answer
63 views

Testing Code That Has Time Delays [closed]

Whilst refactoring an app I'm working on I moved a piece of code from the business logic layer to a helper. The code in question is a fire and forget method that will execute a piece of code if it ...
-1
votes
1answer
59 views

Adding a new class property == new API version?

I have the following code: ...
2
votes
1answer
54 views

This code loops through a GlobalEmployeesList, eliminates duplicate email and phone records for the selected employee, and populates listboxes

I have a DataGridView which displays an employee list. I use the employee ID to filter my global employee list and display information about the selected employee in various listboxes. This is my ...
9
votes
2answers
137 views

ConvertAll Methods Implementation for Multidimensional Array in C#

I am trying to perform some conversions with multidimensional array in C# and I have checked the discussion ConvertAll and 2-dimensional arrays. I found that ...
1
vote
2answers
62 views

Spawning random small cubes in a big invisible cube using Unity C#

My goal was to create a big invisible cube and inside that spawn small random cubes. These small cubes would have: A random position within the big cube. A random colour. A random size. A random ...
1
vote
1answer
61 views

A Paragraph Merger with Removing Overlapped Duplicated Lines in C#

I am trying to make a paragraph merger that takes multiple paragraphs and output a concatenated result with removing the duplicated overlapped lines due to redundancy. Each input paragraph is with the ...
3
votes
1answer
129 views

C# Password Security Login System with SQLite

I want to start by just mentioning I'm a semi-beginner at C# and cyber security so any feedback is appreciated :) What I think I need reviewing is the SQLite queries and maybe the hashing functions I'...
0
votes
0answers
69 views

Trying to replace ManagementEventWatcher class in System.Management to switch to newer Microsoft.Management.Infrastructure

I am working on replacing a dependency in a library for System.Management and migrating to using Microsoft.Management.Infrastructure as recommended by Microsoft. The issue is that Microsoft.Management....
2
votes
1answer
68 views

Factory Method and Log writer class

I Have this class want to practice how to write a factory method pattern and I can change the logPlace by set the app.config, and I try to improve the performance ...
3
votes
1answer
74 views

Is this usage of the dynamic keyword an indicator of a design fault?

I feel like I'm likely violating a design principal or two here so I'd appreciate any mistakes or antipatterns being named and pointed out. I'm attempting to map a system in code which represents a ...
1
vote
1answer
106 views

A Generic Two Dimensional Data Plane with SubPlane Method in C#

This is a follow-up question for Generic Two Dimensional Data Plane with Manipulation Methods For C# and A SubPlane Method for Generic Two Dimensional Data Plane in C#. Based on iSR5's suggestion, in <...
7
votes
2answers
97 views

Method to randomise a string's case

I'm an amateur at programming and have created the following method with which I pass a lowercase string with the idea it is then returned either in it's original ...
0
votes
1answer
51 views

How to make this code follow Solid Principle C# [closed]

Currently I have this code: ...
3
votes
1answer
77 views

Applying 'Uncle Bob's Clean Code' on this small exercice

I'm trying to apply Uncle Bob's Clean Code practices onto this exercise I'm helping someone with. (The exercise assignment is in a "docstring" comment above the ...
0
votes
1answer
58 views

Methods improvements

I just recently learned how to write Methods in C#. Here is one experiment I made. It calculates addition, subtraction, division, multiplication, and the square root of a number. fill free to give me ...
0
votes
2answers
52 views

Generating a random directed graph

I wrote a function that returns a directed graph as an adjacency matrix. The function requires two arguments: the amount of nodes and the amount of edges. At first, nodes are placed and instantly ...
3
votes
1answer
71 views

Namespace list to directory structure

Namespace list to directory structure Motivation I have a list of namespaces I extracted from types, and I which to create a directory structure, that represents these namespaces. So that I can place ...
3
votes
1answer
67 views

Calculating n-ary Cartesian Product too slow

The method gets called extensively throughout my programm, is there any way I can speed it up or improve other aspects? The code calculates the n-ary Cartesian Product of a List containing n Lists, ...
2
votes
2answers
74 views

Replace string based on multiple rules, don't replace same section twice

Given a 2-column CSV dictionary file that contains translation of certain words, this c# code needs to replace the first occurrence of a word in the dictionary. Once a segment of string has been ...

1
2 3 4 5
190