Questions tagged [.net]

.NET is a software framework supporting a multi-language paradigm and supporting language interoperability. .NET applications are executed in a virtual machine (CLR) which provides a few important services: security, memory management and exception handling.

Filter by
Sorted by
Tagged with
-2
votes
0answers
17 views

"Converting" a serverless API to a REST API

I'm interested in implementing a REST API for image classification, using a deep learning neural network. I'm currently relying on an implementation I found online, which is unfortunately a serverless ...
0
votes
1answer
87 views

Whats the best way to refactor a POCO class

In work I was asked to fix a bug which involved me making changes in a class. To fix the bug I needed to add a collection of a class that looks like this. ...
0
votes
1answer
91 views

Linked List Implementation in C#

I wrote an implementation of the Linked list data structure. I mostly did this because it's the simplest collection data structure (at least the simplest to implement), and I wanted to practice ...
0
votes
1answer
137 views

Using a IEnumerable where we have mostly only one item

I have a project where I publish and subscribe some data packages. Mostly those data packages are just one package, but sometimes (1 in 100) there could be more packages at one time (a lot more, like ...
0
votes
0answers
76 views

ThrottledStream

Need a ThrottledStream for a project, created the following class (still not tested), wouldn't mind some opinions on the code and suggestions on how it can be ...
1
vote
0answers
46 views

Simplify LoadLibrary/GetProcAddress helper for dynamic parallel DLL instantiation

Code is meant to be used in Windows .NET (tested with dotnet5.0) to dynamically load C library and return delegate of given function Code lower is result of my attempt to rewrite the ...
2
votes
2answers
113 views

Simple MemoryCache implementation for thread safe caching

After much prompting from this post I wanted to build a simple, in-memory, thread-safe cache. The only caveat (as far as I was originally concerned) was the need for two different absolute expiration ...
3
votes
2answers
184 views

Implement IDisposable correctly using object composition principle

Update at the end Is it possible to implement IDisposable pattern correctly while using object composition principle to promote code-reuse, reduce code duplication ...
3
votes
2answers
138 views

Hangman game with only one word

This is a hangman game. The only word is 'word' and I am not planning on changing this since I am not going to publish this game or anything. If there is any unnecessary/bad code I need to get rid of, ...
1
vote
2answers
213 views

Using multithreading to send multiple emails

I'm trying to send any number of emails in the shortest amount of time using .NET 5.0? I've been playing with something like the following but I am not sure if it is optimal or even correct as there ...
2
votes
1answer
78 views

A simple C# script that exploits PHP command injections

Back in 2016, I wrote a simple C# script that exploits a generic command injection vulnerability on PHP webapps, just for the sake of demonstrating that exploits can be written in .NET languages (due ...
1
vote
0answers
94 views

C# User class using SqlServer Database

I am creating my first business application. Unfortunately, I do not have anyone experienced in .NET or c# to review my code, and this is my first time not only using SQL, but also creating code in a ...
0
votes
0answers
9 views

Data optionally observable

I have a controller whose role is to persist some data into an external resource (could be a file, database, or anything else). This class takes generic objects, which may implement ...
1
vote
2answers
141 views

Possible speed improvements for a Sudoku board validation algorithm?

I tested this algorithm on 9x9 boards and on average, if the board passed to the function is a (valid) solution, it takes 0.13-0.14 seconds for 1 million executions on my machine. I ran my code in ...
3
votes
1answer
100 views

A versatile deck of playing cards. Standard 52-card deck and more

I have seen many posts regarding a standard 52-card deck of playing cards. I recently was composing an answer to one such post when I realized my answer should be its own post since (A) the answer ...
4
votes
1answer
71 views

ForEachAsyncSemaphore asynchronously processing tasks but enable fast fail

I know this has been done many times before, but this is my existing code taken from a sample I found to async process a list of tasks. I've seen Task.Run in use before in many examples, but I'm ...
2
votes
0answers
73 views

How to make this algorithm faster. Calculates and searches through large arrays

Ive got this algoritm thats "complex". The comments in code give examples of how large the various data types could be. My cpu usage is less than 10% when running this and ram usage is good. ...
2
votes
3answers
70 views

How to refactor a method with many prameters that sets a bit array

I've written a method that is going to set a bit array by passing bool parameters to be able send correct command ...
2
votes
1answer
46 views

String formatting

My requirement is to format the input values to a particular format as "##.###/##.###" Example - My input value can have alphabets, alphanumeric, numeric Expired -- > if alphabet, output ...
-1
votes
1answer
39 views

Better way to keep a list of items from a Http Request?

I have a simple web api where each request "item" is stored in a list and thus a list is built without creating a new list per request. I have achieved this via dependency injection , but I ...
1
vote
0answers
150 views

DataGridView Undo/Redo Manager in C#

While answering this code review question, I proposed a solution with List<DataTable>. I am trying to encapsulate this data structure into a "...
3
votes
2answers
262 views

.Net core string symmetric encryption

I need to store sensitive strings in DB, so decided to encrypt it in a DB and decrypt it at the application layer. And noticed that it is not so easy to find ready to use an example. Please check my ...
0
votes
1answer
44 views

Downloading multiple log files

This code succeeds in downloading log text files from multiple URLs. Can this be made more efficient? ...
2
votes
0answers
134 views

How to make a good session handling with NHibernate?

here I leave my code for a repository pattern with NHibernate and Autofac. I would like to receive some feedback about it. Especially about the session handling with NHibernate. By now I don't like ...
1
vote
2answers
191 views

What would be the idiomatic F# way to write optional parameters?

In the context of a library to generate random credit card, it would be nice to let the user the possibility to set some optional options on some cards. Lets take Visa. Two lengths are available: 13 ...
0
votes
1answer
39 views

Remove and add connection string

I want to remove a connection string that may already have been set in a different config file and then set it again. Say my application has a Web.config file and a Web.Debug.config file then I can ...
0
votes
0answers
49 views

.net core console app read from external API and write into a database

I have a .net core console app that gets some data from an external API and inserts it into a SQL database table. It is working as expected but I wonder if you guys have any suggestions to make it ...
1
vote
1answer
65 views

Byte array comparison - efficiency

I have a TCP Listener with NetworkStream that reads 530 bytes from the Client once a second. Within the TCP Listener ...
2
votes
1answer
94 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 ...
0
votes
0answers
75 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 ...
1
vote
1answer
118 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
1answer
87 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: ...
0
votes
1answer
56 views

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

Currently I have this code: ...
4
votes
2answers
121 views

Minimum number of copies of an application a company needs to purchase

Some applications from vendors are allowed to be installed on multiple computers per user with specific restrictions. In our scenario, each copy of the application (ID 374) allows the user to install ...
2
votes
1answer
68 views

Giving an alternative Async method to a service [closed]

I have an interface, implemented by a service, that I inject here and there in my codebase. I would like to give the opportunity to use either the normal method or its async equivalent. ...
2
votes
0answers
240 views

Simple Sqlite-driven WinForms app in C# 7.0 - database interaction code

Description This is a simple "demo" app designed to help gain familiarity with interacting with an Sqlite database from C#, particularly storing images as blobs. The database has a single ...
2
votes
1answer
108 views

Reviewing Basic API

I'm learning ASP.NET and I've created a few simple APIs, so I can consider myself maybe an intermediate beginner. I've decided to create a tutorial serving two purposes: to solidify what I've learned ...
5
votes
2answers
350 views

C# Logical and Math expression parser

I needed a simple parser that could do both logical and math operations expressed in a string, as well as being able to use variables stored in json. None of what I found online seemed to do all of ...
3
votes
0answers
128 views

Console Password Manager in C# in 370 lines

This is a console password manager in C# script. It has 370 lines of code, from shebang to the last }. Are there any ways to make it even smaller without inlining ...
1
vote
0answers
26 views

Preventing the user from entering the same categories [closed]

I'm new to MVC and EF so this may be a really simple question, but what is the best way to prevent the user from trying to enter duplicate records? I have a table called Category with two columns Id ...
2
votes
1answer
72 views

Determine dependency injection type at runtime from config

I have a .NET application with a .config file that has content like this: ...
2
votes
3answers
135 views

C# Update account based on user order data. Nested if-else optimization with almost similar values

The method works, but I would like to know if there is any way to make it more readable, optimized? I have user data (i want to import/update it). Accounts is finded by user data. ======== User order ...
4
votes
1answer
214 views

C# KeyNotFoundException with more information

Preliminary rant: System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary. Oh. My. So I finally got fed up with how ...
3
votes
1answer
65 views

Different versions of the Operate method

I have code that basically is the same, but depending on the number of arguments you provide (up to 5), it will operate with them in a very repetitive way. I have the feeling that this can be ...
3
votes
2answers
253 views

Build byte array from multiple different types of data for sending over a network

The following codes purpose is to generate an array of bytes that represents some user defined data. This array of bytes will later be used for sending over a network. ...
-1
votes
2answers
73 views

How can I refactor a function to be inline? [closed]

I'm refactoring functions trying to do more of a in-line aproach. ...
3
votes
2answers
79 views

Exporting objects in various formats while reporting progress

Description A WinForms application has a function to export objects of the following type, in various formats: ...
2
votes
0answers
23 views

Applying OOP to refactor my Windows Forms APP [closed]

Could you please give me some direction about how I could refactor my code? As I add functionalities to my Budget App the class is getting bigger and I'm sure I could start looking at separating ...
1
vote
0answers
93 views

Code refactor - eliminate generic interface and object methods

I'm building a method that tries to detect whether given information about an object's property to retrieve, a constraint operator and some data to compare it against, whether the result is true or ...
7
votes
3answers
2k views

C# Am I using proper SOLID principles?

I am currently practising using the SOLID principles in C#/.NET I have made a little example, but i am not sure if i have followed it correct. Its a simple example where i have an API controller that ...

1
2 3 4 5
24