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

C# PRNG class based on xoshiro256**

Background I'm creating a (probably bad) map-generation utility in C# to generate fractal terrain and similar. Nothing I do probably needs special treatment, but I thought it best to start with a good ...
0
votes
0answers
5 views

Most efficient way to track a collection of targets in range of a source object

In my game there are space ships and each of these space ships tracks which other ships are in range of it. I need to perform certain logic when a target ship comes in range of another ship, and ...
0
votes
0answers
17 views

Initialize and run/stop subprograms in ViewModels

I make WPF application and I need start "subprograms" (scan directory & send to the API for now, in future - accept incoming files) in MainViewModel, ...
0
votes
0answers
18 views

Async generator that processes input enumerable in batches-at-a-time

I have a lot of Input documents, which contain collections of sentences. I would like to use an online sentiment API to attach sentiments to each of these sentences ...
0
votes
1answer
25 views

Creating database and two tables linked by foreign key

These commands do what I want, but I'm trying to find out the best approach for this. My main areas of concern are: error handling and disposal of resources. In regards to error handling, I'm catching ...
0
votes
2answers
46 views

Create walls in a game from a random maze

I use four bools, if true a wall is in that direction: ...
1
vote
1answer
45 views

Try-catch-finally with 'using' in ADO.NET

I want to check if I'm correctly disposing of resources using Ado.NET. I'm not sure when the 'using' statement makes .Dispose() irrelevant. Please bear in mind I'm aware I shouldn't hardcode my SQL ...
0
votes
0answers
33 views

Date range generator

An app has a feature that's much like any calendar application (like the Outlook calendar for example). Consequently, I need to do a lot of date logic. I wrote a class with date calculation methods ...
2
votes
1answer
55 views

Ping pong game (console)

I've made a 2 player game in c# console that is a ping pong game. I've made it in more or less 4 hours and in my opinion it is the best performing game I've made so far. Just to let you know, I am a ...
1
vote
0answers
43 views

Get a list of the 25 most popular items on an E-Commerce site

I have a few lines where I am trying to get a list of the 25 most popular Items sold on an E-Commerce web site. The code works but I would like hints on how to optimize it. ...
1
vote
0answers
31 views

My code generates a path through a grid - How can I simplfy it in terms of list, dictionary's, stacks and queues?

This code works but is cluttered and I think could be improved in terms of how it is implemented. Basically my code works - what it does is from the start location, it chooses a random direction and ...
0
votes
0answers
92 views

Is there a faster way to read bytes with a FileStream?

So I'm trying to read data and store it in an array as fast as possible and the fastest method I found of doing so was this. ...
-1
votes
0answers
28 views

Group by With Client-Server Evaluation [closed]

I am having a problem with .Net Core 3.1 EF and the problem here seems to be the client-server evaluation that is not supported by Core 3.0 and the next versions. How can I avoid this problem? ...
3
votes
1answer
104 views

Memory leak I can't identify using Bitmap and Graphics classes

I have some parallel.for one inside another. the last parallel.for have a normal for that ...
1
vote
3answers
93 views

Export DGV data as a table to a word file using Xceed's DocX library

my winform app contains a combo box, a button and two datagridview among other controls. Both DGV's have 3 columns. When I select an item/items from one or both of the DGV's and hit the button the app ...
3
votes
2answers
108 views

User interface for a simple tool that generates Word documents from Excel data

This question provides the code behind the dialogs in the C# refactoring question. I'd like a review of this code as well. I'm not currently using databinding anywhere, and there is really only one ...
3
votes
3answers
101 views

Follow Up: Refactored C# Tool to Generate MS Word Document Mailbox List From MS Excel

Background Some very good observations were made about my original code in the 2 answers to this question. In this version I have attempted to reduce cyclic complexity and class coupling even more as ...
2
votes
2answers
114 views

Optimize the data adding process to datatable from excel file

I'm creating a simple windows form application containing a combo box, a text box, a datagridview, a button and some radio buttons. The idea is upon the form loading the combo box is to be populated ...
1
vote
2answers
97 views

IPAddress Range access

I want to make this code better and easier to read. It works now but I think it can be better. When there is an Inbound request I check to see if that accessKey is setup for IP address Range that will ...
1
vote
0answers
75 views

C# library for working with Linux evdev

Project: https://github.com/afshin-parsa/evdev-sharp Language: C# 10 Framework: .NET 6.0 I was looking for a way to control my BeagleBone Blue robot with an XBox One S controller. so I searched around ...
3
votes
2answers
123 views

Binary Search of Array in C#

I am an algo-newbie and this is my first attempt at writing binary search and it worked on the first try. But something about it tells me that its far from perfect. Please tell me how I can improve. <...
1
vote
1answer
55 views

Saving and/or Printing a Word Document From C#

This is the Microsoft Word portion of the application described in this question. It is considerably simpler than the excel portion of the project. Any classes not defined in this question can be ...
3
votes
2answers
95 views

C# Tool to Generate MS Word Document Mailbox List From MS Excel

There is now a Follow up question to this question. Abstract The VBA solution didn't work on the clients computer because Office 2010 Starter Edition doesn't support VBA. I decided to try a C# ...
-1
votes
1answer
64 views

Basic ASP.NET Core RESTful API with Entity Framework Core

This is my first WIP backend asp.net application, which I will pair with react to create a full stack app. The thing I'm mostly worried about is model conversion to DTO and custom policy authorization,...
2
votes
1answer
60 views

Resilient & Stable TCP Server Polling

I am looking for feedback to perfect my code developed for WPF in terms of speed, stability and resiliency. My code is supposed to handle synchronous status polling as well as asynchronous Commands to ...
5
votes
2answers
104 views

Scrabble Kata (C#)

I recently took a ~three month break from professional software development and am feeling a bit rusty. I thought a good way to ease back into things before looking for a job would be to take a swing ...
3
votes
0answers
56 views

Handling boilerplate tasks via service pipelines

Here's a small experiment about handling boilerplate tasks via service pipelines. It's similar to the HTML pipeline but simpler and multipurpose. I've updated the question and this is the 2nd version ...
1
vote
1answer
41 views

Multiplayer game byte array serializer with unity

I I'm trying to make an multiplayer game using golang and unity. Golang server side checking units on scene(like a character move). It also sends the information (position, health) of the units on ...
5
votes
1answer
164 views

Task-based TCP socket wrapper class

Recently I've been entertaining the idea of making a small encrypted chat app as a way to learn about UI, encryption and networking in C#. After some research/work, I've produced the below protocol ...
11
votes
7answers
2k views

How much error handling is too much?

I have the following C# code (.NET 6): ...
0
votes
1answer
43 views

Action on each element of an inline list

I'm trying to learn the "functional" part of C#/.Net for work, and I'm not sure if this is a good way to write this statement. I was also trying to reduce duplicated code while not ...
3
votes
0answers
34 views

Get shortest grouped (distinct) string from Hashset of strings

Well, I just have a lot of strings that have common parts between them and not all of them. By this reason, I wanted to group them by their longest common part and take from that the minimum from each ...
1
vote
1answer
31 views

.Net BouncyCastle - PKCS#3, PKCS#8 & PKCS#10 Generation as base64

Reaserching BouncyCastle for C# is not for the faint of heart. After navigating an ocean of Java dead ends, I have arrived at the following code. I believe it's very useful for someone who wants to ...
4
votes
1answer
115 views

C# Thread-safe singleton service for caching data used during lifetime of ASP.NET Core MVC application

Basic Background I have an ASP.NET Core MVC application that uses Client (e.g., "customer") information for every HTTP request. The collection of Clients, as well as their information, ...
5
votes
0answers
134 views

C# Async FileInfo Extensions (Copy, Move, Delete)

Here is my effort to implement extensions for FileInfo object: ...
1
vote
2answers
108 views

sum of array using multithreading

I implement sum element of array using multi threading but my question is when my program work with one thread the time is better than using 6 thread . I am using a CPU with 8 threads.What am I wrong <...
5
votes
1answer
103 views

I made a little mastermind game in C# to exercise - do I take the right approach?

I'm very new in C#, and the best way to learn, is to do exercises. As I tried to find a challenging exercise, I created this little game called MasterMind. The rules are very simple, and are explained ...
1
vote
0answers
19 views

Unity3D Observable Variables as ScriptableObjects

I'm trying to implement an observable pattern on variables, so that I can hook up UI components, etc. to change displayed values or other actions when their value changes. I wanted three features that ...
2
votes
0answers
18 views

Unity player controller code

I wrote this code I am making for an open source game. I just would like some feedback to know if my code is good. One thing I have to question is my use of private functions okay? I use a lot of them ...
2
votes
3answers
52 views

Feedback for lambda expression to count object by DateTime.Value.Month

I want to count user registrations by month, currently the code I have works, but I want some feedback or some ideas on how to do it in a better way because I think mine looks a bit messy. Using a ...
2
votes
0answers
41 views

Asynchronous TCP server refactor design & not working features

I'm working on an asynchronous TCP server which is supposed to be used for a chat. I want to get a review for the TCP server part because I'm struggling to find a good design to fulfill the following ...
3
votes
1answer
67 views

Custom blocking priority queue

I created priority queue which stores messages sent from asp net core controller and then processes them in BackgroundService The thread which loops through items is blocked when collection is empty. ...
3
votes
1answer
131 views

Deque class for .Net (C#)

As .Net has no Deque class (Double-Ended Queue) in the Frameworks and I couldn't find an example implementation that I was happy with, I have written the following with the intent that I may post it ...
0
votes
0answers
20 views

A bit of inventory management code I made using ScriptableObjects in Unity that lets you find items, check if you have items, and take items

It took me a while to figure this out, it's probably the most flexible code I've made. There might be some small mistake somewhere as I didn't get to fully test it, I'm just looking for glaring issues ...
0
votes
2answers
98 views

Simple stock taking program in C# Windows forms

so I've made a simple program meant to increase and decrease numbers, then save those numbers, basically a rubbish stock taking app, I want to make one I can use and well it's usable I'd say the code ...
0
votes
1answer
32 views

ASP.NET Web API 2 reading values from config file or database or elsewhere

In my asp.net web API 2, I am reading values from web.config from the controller into my DTO as a response to the client. It is working as expected, I wonder if there are any improvements to make it ...
3
votes
1answer
61 views

Improving performance of 'Prioritized left shuffle algorithm'

I wrote a prioritized left shuffle algorithm (the code is copied from my open source C# project Fluent Random Picker). That means: You've got some values and each of them has a priority (a number). ...
3
votes
0answers
49 views

C# Setting all class members to null to destroy strong references

At work we are using Xamarin.iOS for our apps. We frequently have to fight it's disadvantages, namely it's memory leak issues where strong cyclic references keep objects alive and prevent them from ...
0
votes
0answers
40 views

Calculate offset and fetch values

The calculatePage function - Calculates if a parent and child comment have more than 15 comments then consider it as page. The next 15 comments should be moved into the next page. The logic works fine....
0
votes
0answers
47 views

Wrapper around SignalR's implementation

I made a web socket client wrapper using SignalR's implementation, but there are some downsides that I want to improve. CancellationToken's implementation is wrong/incomplete ...

1
2 3 4 5
196