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
1
vote
0answers
13 views

Accurately measure ASP.NET Core 3.x actions execution times (Web API project)?

I want to be able to log the time spent by a certain Web API action in an ASP.NET Core 3.x application. This is a very old question from ASP.NET which relies on global action filters, but in ASP.NET ...
2
votes
0answers
31 views

C# Rest Client Benchmarking

I build a C# Rest Client library / framework. I noticed that it seemed to be significantly faster than RestSharp for GET at least. So, I decided to put together some benchmarks comparing it to other ...
1
vote
0answers
43 views

HTTP Client - Best practices

I've made a HTTP client and would like some tips to improve my code, it's supposed to be built for xamarin forms but should work with any implementation. My goal of this project was to learn more ...
0
votes
3answers
94 views

c# IndexOf string search

I have this code working but its using IndexOf I am not sure if that is the best or only option for search for a string value. What I have is a list that will need to remove a world from the child ...
-3
votes
0answers
22 views

align with spaces [closed]

There are two cases. Case 1: ...
1
vote
1answer
105 views

Connect 4 class in C#

I wrote the following class for a connect four game in C# ...
1
vote
0answers
48 views

get better performance [closed]

I have this code that works, but I'm sure that it can be done better, any suggestions? ...
3
votes
1answer
36 views

Multi-threading with TPL - Access Internal Class Properties

I am using the TPL library to parallelize a 2D grid operation. I have extracted a simple example from my actual code to illustrate what I am doing. I am getting the desired results I want and my ...
2
votes
1answer
43 views

Validate implementation of ECIES

I've created a basic implementation of ECIES (Elliptic Curve Integrated Encryption Scheme) based on http://www.secg.org/sec1-v2.pdf section 5.1. ...
1
vote
0answers
59 views

Abstract vacation time tracker with states

I am writing a program for vacation in a company and the time that is allowed to be in a specific holiday I used an Abstract class with an abstract method: ...
0
votes
1answer
25 views

c# Ftp.UploadFile

I am trying to improve working code seeing if there was any potential issues or performance problems. This code will connect to an ftp server and upload a file. ...
0
votes
0answers
28 views
+50

Async Check for Domain Fullname With WPF and Caliburn.Micro

I have a small WPF program built using Caliburn.Micro which checks Active Directory for a user with the current username of the logged-on user. I have a Bootstrapper...
3
votes
2answers
43 views

Adding a cancellation token to TcpListener.AcceptTcpClientAsync()

There is no facility in TcpListener (or for that matter Socket) to close a listening socket that is waiting for a connection without throwing an exception. After running up a test bench with 8 ...
0
votes
0answers
39 views

Array of varied dimensions

I wrote a UltraCube class whose purpose is to provide an array of custom number of dimensions. This was created because I needed to make number of dimensions for ...
4
votes
1answer
126 views

Method that filters a list parameters based on different fields

I have this code which is a callback for Filter in WPF ICollectionView. When I run code analysis, the cyclometic complexity is reported to be 11. I consider this ...
-4
votes
0answers
37 views

How to customize Microsoft Identity in the Business Logic Layer and use the database connection from the Data Access Layer [closed]

Please I have been deadlocked on how to implement a 3 Layered Architecture in dotnet core mvc. Particularly is how to customize Microsoft Identity in the Business Logic Layer and use the database ...
-1
votes
0answers
18 views

HtmlAgilityPack - How to get the Value from the tag <div> into aspx.cs [closed]

I have a task to do. I need to get the value from the tag into c#. I need to display the value into Label This here is my HTML code: ...
0
votes
0answers
41 views

Downloading large amount of data and storing on Android & iOS

So I have this API that downloads from our web service, but the we service sends it as a ZIP file instead of a json stream or something else. Now the files can get quite large butt they are not ...
-5
votes
0answers
24 views

Moq Test Dependency Injection [closed]

I am new to Moq Testing I just want to know how to test my Dependency Injection.can any one help me pls. Here is my code: ...
1
vote
1answer
40 views

C++ Wrapper and Correctly Disposing Unmanaged Resources using ArrayHandle

I have the following class ...
1
vote
1answer
92 views

Increase Perfomance of Nested Object Instantiation C#

I'm filling a list of items from the database, which is taking extremly long time to run (Approx 60 seconds) Here is the code with the relevant breakdown 97% of the performance issues come in the ...
3
votes
1answer
188 views

C# Windows Forms App: Adding An Element To The BindingSource And Save These Changes To The DB [closed]

I have build a C# Windows Forms app that used Entity Framework(DB first model). For the data I am using a .mdf database file. The data view of dbo.students: GUI: The Form1 class: ...
-1
votes
1answer
36 views

Extract a substring from a string without using the library function.[C# Console Application] [closed]

My Solution for Question 13 on https://www.w3resource.com/csharp-exercises/string/index.php ...
-1
votes
0answers
31 views

Use of the is keyword to check if a nullable is not null [migrated]

I just figured out, that it is possible to use the is-keyword in C# for a null check on nullable stucts. I think it looks quite clean and is good to understand, but ...
1
vote
1answer
63 views

Right way to handle, log and display exceptions

I repost my question here because it has been closed on stack overflow This question could sound stupid but I am new to the logging, displaying and handling exceptions. Because before I was just ...
2
votes
1answer
38 views

Handling external API calls status code in my application

I have a Web API application in .NET Core 3.1. In a controller I have a GET action that must return a JSON object with a name and a description. In order to retrieve the correct description I need to ...
7
votes
4answers
239 views

Reducing code duplication for my C# math class

I have a library with a lot of duplicate code to accommodate different collection types, and its starting to get a bit tedious, is there a better way to do this to reduce the amount of duplication ...
2
votes
1answer
56 views

Inserting large amounts data into Excel spreadsheet

I have a VSTO Excel Add-In which is used to retrieve data from another application and insert it into an Excel worksheet. Due to the potential for lots of pieces of data to be inserted into a ...
3
votes
0answers
126 views

bowling game score calculator

I'm new to the Developers world and I have project that I've been working on. It's to calculate the Bowling Game Score (similar to the Hdcp Score done by this tool: https://bowlinggenius.com/ ) I'm ...
1
vote
0answers
49 views

Zen and the Sieve of Eratosthenes - Part 1: A Basic Windowed Sieve

The Sieve of Eratosthenes is one of the oldest known algorithms and yet it is still the best method for sieving prime numbers in bulk in many situations. It is brutally simple, but to make it brutally ...
3
votes
0answers
54 views

Correct and safe way of performing token exchange?

I am dipping my fingers in external apis that a user would login and retrieve a code to exchange for a token. In my case, it is for the SpotifyAPI. All the web app does it return the users top ...
1
vote
1answer
34 views

Using Reactive Extensions in an Asynchronious Way

I am new to Reactive Extensions, I have the requirement to consume PairCollection<IPointCloud> which are fed into a service which performs a very expensive ...
1
vote
2answers
69 views

Autofac support for connection strings

I would like Autofac to instantiate components based on connection strings in the form of the URI: ...
2
votes
0answers
88 views

Strongly typed unit system in C#

I am working on a Units library for a personal project that is a physics-heavy C#/Unity3D game, and I am looking to improve it in a few areas: 1) Is there a way to reduce the code duplication? 2) Is ...
1
vote
3answers
153 views

Rock/Paper/Scissors using C#

I created a Rock/Paper/Scissors game in C# that asks the player the number of rounds he wants to play, and then calculates the points and determines the winner. Is there a way I can fix my code? Is it ...
1
vote
2answers
83 views

C# Ping - Checking availability of hosts

Simple Console Application for checking if one of the hosts is available. The implementation should be for around 5 hosts to check with different response times and the method should return fast when ...
1
vote
1answer
93 views

String Split a phrase into sentences

Hello this is a Console App(.Net Core) in Visual Studio 2019 and i am trying to split a string into sentences and then add them into a dictionary with Key the first word of the sentence and Value the ...
5
votes
2answers
71 views

NewSequentialId - pure net core 2.2 implementation of sql server function

i'm currently trying to rewrite sql server newSequentialId() function in pure c# that is performing as fast as possible and eats minimum memory. Question is can I it be done better - current ...
0
votes
1answer
34 views

c# QuadTree yielding properly [closed]

I have implemented a QuadTree of my own, and I'm afraid I didn't use yield properly when I query my tree, my fear is that I create O(HN) iterators. Could you direct me how to better improve the ...
-3
votes
1answer
54 views

Find the starting index of all occurrences of a pattern within a string

...
4
votes
1answer
107 views

C# program which measures the distance between the average and maximum/minimum temperature

The program below takes inputs for the temperature in various cities in a span of multiple days. It then outputs the ones where the minimal temperature is closer to the average than the maximal ...
1
vote
1answer
54 views

Image type convertion

So I have a piece a code that, altough it does what is expected, it doesn't seam very performant to me. I just wanted to know if there's a better way to do this or if my code is alright as it is. The ...
2
votes
1answer
68 views

Flash Light Effect Windows Forms Edited

I am having performence issues with image processing task (flash light effect). I used c#, and used couple references (LockBits Method, Extension). The program has bad frame rates. Edited the code, ...
1
vote
0answers
49 views

Unity rotator script

I was playing around with Unity's new Entity Component System and I was trying to implement a rotator system. This is what I came up with: Component Data: ...
1
vote
1answer
63 views

Actuarial claims reserving with the chain-ladder method [closed]

Hello there and beforehand a huge thank you to everybody for dedicating their time to help others. This is my first post here, so I hope I comply to the guidelines. Maybe a bit background to myself: ...
-4
votes
0answers
24 views

Unit test to extract year from httprequest header

I'm currently unit testing a controller that extracts values from the incoming request headers using NUnit and Moq. My TestFixture: ...
1
vote
1answer
117 views

How to capture disk folder structure?

What would be the shortest way to capture folder structure in code? I would like to have a more or less reusable strictly typed approach to use in scripts instead of stringly typed paths we all ...
3
votes
0answers
32 views

Accurate && precise location data within a timeframe (session)?

Scenario A session would start & end within a time frame. Within this time frame, the device would be moving within a constraint environment. The movement would be extremely slow (slow-walking ...
8
votes
3answers
150 views

60GB file loading domain to base domain + tld parser

I have a 60GB file of domain names. Some of them are repeated several times and some of them have sub domains that need stripping out too. For example this might give you a better idea of what the ...
1
vote
1answer
37 views

ASP.NET EF seed one to many relation

I am creating a simple model relation in ASP.Net core. My model relations are like this: A user can have many posts A post can have many comments A user can have many comments Now I am trying to ...