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
1
vote
1answer
32 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. ...
1
vote
2answers
25 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
35 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 ...
4
votes
1answer
596 views

Simple Vector2 structures (and interface)

I built a couple Vector2 structures (Vector2 and Vector2F) for use with a particular project,...
-1
votes
1answer
36 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 ...
7
votes
1answer
2k views

Fastest De-/Serialise struct in .Net

I wrote this code to De- and serialise structures afap using IL generation (comments describes C# analogue). What can be improved here? ...
2
votes
0answers
57 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
88 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 ...
1
vote
0answers
58 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 "...
0
votes
1answer
42 views

Downloading multiple log files

This code succeeds in downloading log text files from multiple URLs. Can this be made more efficient? ...
1
vote
1answer
790 views
1
vote
2answers
81 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
30 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 ...
12
votes
2answers
30k views

Mapping ExpandoObject to another object type

I am working on a helper method that maps properties from an ExpandoObject to a user supplied object and was wondering if the code could be cleaned up or made any ...
1
vote
1answer
58 views

Update cache with minimal blocking

As part of the task, it is allowed to use slightly outdated data. It is required that only one thread per key is involved in the critical section, while the remaining threads use data from the cache ...
1
vote
1answer
58 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 ...
5
votes
1answer
343 views

Displaying information about an order when selection changes

I feel like just because the below works doesn't mean it is correct, I want to improve it but I can't really figure out how. Besides the fact it is down right ugly I feel the performance could be ...
0
votes
0answers
45 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 ...
4
votes
1answer
6k views

Thread-safe wrapper around WCF ServiceModel.ClientBase subclass

I have an ASP.NET application which uses a Service Reference to a (third-party, offsite) payment processor. The service reference class is generated automatically. Its implementation is a subclass of ...
3
votes
1answer
148 views

In Memory Database in Unit tests, isolate the tests

I have stumbled across these unit tests in a code review that are using in memory db: ...
2
votes
1answer
76 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
69 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
116 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 ...
1
vote
1answer
2k views

Caching XmlSerializer in AppDomain

To work around the XmlSerializer memory leak thing I created this: ...
5
votes
4answers
330 views

Is this a good implementation of a simple “Size” value type

I have created the value type below to represent the desired size for an image. The Size.Default is used in situations where the image is required in the size it ...
0
votes
1answer
85 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: ...
7
votes
3answers
4k views

ThreadSafeObservableCollection of (T)

The idea here is to implement a simple, threadsafe, observable collection that clients can bind to, whilst background threads can update. Changes in the contained items raise the ...
0
votes
1answer
52 views

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

Currently I have this code: ...
4
votes
1answer
63 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 ...
1
vote
1answer
88 views

Should I use and loop, or just a loop? [closed]

I have this code: ...
1
vote
2answers
1k views

Cancel Long Running Query using Cancellation Token AND SqlCommand.Cancel()

I need to be able to cancel a long running query programmatically through our application. The code below will kick off a long running query and give control back to the main thread. At any ...
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 ...
1
vote
1answer
3k views

Work with nested task [closed]

I have Client and Server classes. The Server return a ...
16
votes
1answer
263 views

Open source project to ease the Assert part from the functional tests of .Net Core Web APIs

I have built an open-source project based on FluentAssertions in order to solve some recurring tasks I was doing while testing the .Net Core APIs I'm developing. I find the capability of doing in ...
18
votes
4answers
36k views

Building a Tree from a flat List<Nodes>

This is my incoming data: ...
12
votes
1answer
26k views

Converting binary value from BitArray to an int and back in C#

What I am creating is essentially a binary clock face with touch input for setting values as well as displaying - so I need to convert both ways between an int and a binary sequence in a BitArray. I ...
2
votes
1answer
67 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
97 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 ...
5
votes
2answers
228 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 ...
2
votes
0answers
313 views

C# class to dump the memory of a process in several formats

I made this because I couldn't find any good C# classes/libraries that allow you to dump the contents of a process' memory into a file or a byte array. I haven't tested this on 32 bit systems but it ...
3
votes
0answers
113 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
24 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 ...
22
votes
2answers
50k views

Creating a thread-safe list using a Lock object

Will this code qualify for a truly thread-safe list? It is using the Lock object. ...
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 ...
2
votes
3answers
131 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 ...
2
votes
1answer
43 views

Determine dependency injection type at runtime from config

I have a .NET application with a .config file that has content like this: ...
28
votes
5answers
45k views

Type-safe Dictionary for various types

Assume the following situation: you have an object that can store any object based on a key (basically, IDictionary<string, object>). You want to store ...
4
votes
1answer
62 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
2answers
215 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. ...

1
2 3 4 5
23