As of May 31, 2023, we have updated our Code of Conduct.

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
7 votes
3 answers
11k views

Vending Machine

After doing a lot of reading and practicing, I've come up with a simple program that implements multiple OOP techniques, principles and several design patterns such as Observers, Factories and ...
Tommy Naidich's user avatar
7 votes
4 answers
16k views

Count duplicate List<int>

Count duplicate List<int> in List<List<int>>. A duplicate is not order-dependent. { 1, 2, 3 } is a duplicate ...
paparazzo's user avatar
  • 5,946
7 votes
2 answers
2k views

Tuning Excel calculation engine which uses MS Excel interop

I am currently building an Excel calculation engine. Its purpose is basically to wrap the calculation logic of an Excel workbook in order to use the logic from a C# library. ...
Marc's user avatar
  • 191
7 votes
2 answers
2k views

Combining List<>.ForEach and List<>.Zip

I have three lists, and I need to operate on the ith element of each list simultaneously. ...
Snowbody's user avatar
  • 8,432
7 votes
5 answers
7k views

A generic singleton

What do you think about this for a generic singleton? ...
Simon Hughes's user avatar
7 votes
1 answer
9k views

Removing accents from certain characters

I have a method that I am using to remove accents from certain characters. The problem is the massive slew of characters I am expected to work with. I have to, basically, remove accents from all Latin ...
Der Kommissar's user avatar
7 votes
1 answer
310 views

Somewhat esoteric if statement in a paginated feed

I am working on the home page of a website that will have a paginated feed (much like a blog's home page). One of the requirements is that when a user navigates to a non-existent page, he or she will ...
Caster Troy's user avatar
7 votes
2 answers
628 views

Optimizing special cases of modulo

I have a use case where improvements to the speed of calculating modulo for 64 bit integer dividends makes a significant difference in overall processing time. The divisor isn't known statically - it ...
quentin-starin's user avatar
7 votes
1 answer
6k views

Serializing objects to delimited files

For a new project I'm going to need to be able to serialize random types to TSV or CSV files, so I write a class which can be used to serialize any object to a TSV, CSV or any other _SV file you can ...
Der Kommissar's user avatar
7 votes
2 answers
33k views

Is there a better way to search directories for a file or files?

Edit: The purpose of this method is to search a specific directory for a given file type, ex. (*.txt, *.pdb, *.exe") then move the file(s) to a given destination directory and delete the original ...
Eric Anderson's user avatar
7 votes
2 answers
6k views

Safe Dispose of Timer

I am currently refactoring a larger solution where the compiler gave multiple warnings about disposing the used System.Timers.Timer instances. The timers are ...
AFrueh's user avatar
  • 73
7 votes
3 answers
554 views

Go through every pixel of an image and then dispose of it

I'm a little confused as to whether implementing the Dispose method serves a purpose in this code. It never gets referenced by any other class in my project, so ...
Bogdan Dimov's user avatar
7 votes
4 answers
8k views

Get nested type name without namespace

Suppose I have a nested class structure like this: ...
p.s.w.g's user avatar
  • 1,951
7 votes
2 answers
7k views

Recursive database actions

I am been using a code pattern for recursive database actions in my applications. I create two class objects of a database table, singular one (e.g Agent) for holding single record with all fields ...
KoolKabin's user avatar
  • 317
7 votes
1 answer
708 views

Is Lock necessary to make operation thread safe for this scenario

I have the following method that is responsible for retrieving an Item from the database. There will be multiple threads instantiating this class, so I want to make ...
whoami's user avatar
  • 175
7 votes
2 answers
3k views

ASP.NET Core 3.1 AddHttpClient call that includes a call to the database

So, I have an ASP.NET Core 3.1 web site that makes occasional calls to a vendor's RESTful API. I use the HttpClient class to perform these calls. Currently, the ...
EJoshuaS - Stand with Ukraine's user avatar
7 votes
2 answers
6k views

Generic Dictionary Equality Comparer

I created the below comparer to allow me to use a generic dictionary as a key to another generic dictionary. My GetHashCode implementation creates a hash based on ...
JohnLBevan's user avatar
  • 1,333
7 votes
2 answers
1k views

Finding MinMax values and returning a tuple as a result

I was coding some tooling stuff when I started to ponder whether the best return type for a Range / MinMax method applied on a IEnumerable method. I am using the value the C# 7 Tuples like below, but ...
Natalie Perret's user avatar
7 votes
2 answers
2k views

CRUD commands to SQL database

I have a large application that focuses on using dependency injection. I've made a small (as I possibly could) piece of sample code to make this question more manageable. Essentially, I have a lot of ...
JBond's user avatar
  • 295
7 votes
2 answers
314 views

Is there a better way to call the same method with different parameters?

I have a method(C#) which takes an XmlNodeList and a String and saves the xml data into a database. That code isn't the problem (at least for the moment), but because I have multiple XmlNodeLists, ...
edparry's user avatar
  • 185
7 votes
3 answers
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 ...
manwood's user avatar
  • 259
7 votes
2 answers
661 views

Memory test in windows forms

I've made a memory test game in windows forms, where you need to find and match 2 cards with the same images. It has 3 difficulties : Easy - 4 different pairs of cards, no time limit, no mistakes ...
Denis's user avatar
  • 8,438
7 votes
2 answers
843 views

Sum-based sliding rate limiting with Redis and Lua

As I'm new to Redis, I would like to get a review / improvement suggestions from Redis / Lua experts on the following problem and the solution I have found so far. Problem The context is: an e-...
Maxim Gueivandov's user avatar
7 votes
2 answers
18k views

Setting the value of properties via reflection

I am working on an application in which I have to parse an XML file. Nodes of the XML file corresponds to an object. I have to populate the properties of the objects at run time. The code below ...
Sandeep's user avatar
  • 410
7 votes
1 answer
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? ...
Alex Zhukovskiy's user avatar
7 votes
2 answers
808 views

String tokenizer via UDF

I am trying to implement strings tokenizer in Excel via UDF using C# and Excel-Dna. Personally I found the mIRC's function $gettok pretty useful due to the lack of ...
Eder's user avatar
  • 205
7 votes
1 answer
2k views

Create path to file under 64-bit %programfiles% from 32-bit process

I have a process that runs as 32-bits regardless of the architecture. In it, I want to be able to spawn a process from the 64-bit program files menu (e.g. ...
Jimmy's user avatar
  • 283
7 votes
2 answers
4k views

Implementing IDisposable correctly to return TCP connection back to pool

I'm trying to implement TCP connection pooling and return a connection back to the pool using IDisposable. I'm wondering if my implementation is correct. It seems ...
newbie's user avatar
  • 181
7 votes
2 answers
2k views

HKDF Implementation in C#

Based on my prior question about HKDF here https://crypto.stackexchange.com/questions/43933/use-of-pbkdf2-when-no-access-to-hkdf and the responses I received I decided to go ahead an implement HKDF ...
RonC's user avatar
  • 171
7 votes
2 answers
433 views

A generic IEnumerator to enumerate COM collections

As I wrapped the VBIDE API, I encountered a number of "collection types" (Windows, CodePanes, ...
Mathieu Guindon's user avatar
7 votes
1 answer
5k views

Async TCP client/server

I'm working on a simple async TCP client server application, i'd like my network code to be reviewed. I really feel that I'm doing something wrong, especially in receiving code. Interface for client: ...
HardLuck's user avatar
  • 175
7 votes
1 answer
789 views

Implementing an IRC Bot

This is a (fairly) simple IRC bot. The whole idea of it was similar to Duga, except that it will post to an IRC server instead. The bot takes messages from a SQL table and posts them in the IRC ...
Der Kommissar's user avatar
7 votes
1 answer
3k views

Replacement string Base64 (and a Base32) conversion [closed]

This provides (my own) implementation of ToBase64String and FromBase64String (since the .NET implementations suck), and a ...
Der Kommissar's user avatar
7 votes
3 answers
10k views

Optimization of comparing two collections and get the changes

I use the following code to get the changes between two collections. Objects are "joined" using a primary key. Any tips on performance issues or other optimizations appreciated. ...
Magnus's user avatar
  • 375
7 votes
1 answer
21k views

Making async SQL calls

I've written a class to make async SQL calls and it appears to work like a charm! But I'm a bit concerned about what it means to send a lot of queries to the server and then aborting them by throwing ...
Mcb2000's user avatar
  • 73
7 votes
1 answer
4k views

Code that uses reflection to validate arguments

I wrote an answer to this question on the Software Engineering SE site and was hoping to get it critiqued. (I'm told that it's acceptable to do so). Essentially, this code uses reflection to check to ...
EJoshuaS - Stand with Ukraine's user avatar
7 votes
3 answers
561 views

Secure password hashing implementation

I'm implementing a password hashing method for a website. The code below is part of the User class. Any pointers on what I could do better? ...
Mike D.'s user avatar
  • 252
7 votes
1 answer
356 views

AutoResetEventAsync, am I missing something?

So I wrote an asynchronous version of AutoResetEvent: ...
SHSE's user avatar
  • 223
7 votes
3 answers
3k views

Cached empty collections

I often need to return empty collections. One of those days I wrote the following to return a cached instance: ...
Şafak Gür's user avatar
7 votes
1 answer
81k views

ASP.Net, C#, and alert/display messages

We have a hidden div in a master page. When we want to display a message, we send a function a message to display, and it turns that div from .Visible false to .Visible true, and fills the div with ...
CptSupermrkt's user avatar
7 votes
3 answers
1k views

3-layer ASP.NET app - Need critique/advice

My current setup is a 3 layered application: UI > BLL > DAL. Each layer is set up as a separate project. The UI is an ASP.Net website and the BLL & DAL are Class Library projects. I've shown some ...
mahesh's user avatar
  • 71
7 votes
1 answer
1k views

A super string cleaner

I need a method that clean up a string considering these few rules: Remove or not Spaces Remove or not Special Chars Remove or not Numbers Descaptalize or not the string (this is don't really needed ...
Jonny Piazzi's user avatar
7 votes
1 answer
557 views

MVVM: Am I doing it right?

I read a lot of articles recently concerning XAML, WPF, data binding and MVVM. I also watched some MVVM tutorials and downloaded some MVVM samples. I finally got my first MVVM sample to work, but ...
Kim Homann's user avatar
7 votes
1 answer
10k views

Async distributed locking with StackExchange.Redis [closed]

I have been trying to write an analogy to this approach to distributed locking with two differences: making it asynchronous making it work with StackExchange.Redis rather than AppFabric Cache. My ...
ChrisT's user avatar
  • 123
7 votes
1 answer
2k views

Encryption and decryption on streams using AES CBC + HMAC SHA

The goal of the code below is to: Support authenticated encryption using AES in the CBC mode and using HMAC SHA. Support encryption and decryption of data of size larger than memory (potentially). ...
Patryk Golebiowski's user avatar
7 votes
1 answer
1k views

Pin an array in memory and construct a Bitmap using that buffer

I'm using some resources in the code below to pin an array in memory and construct a Bitmap using that buffer. I'm not sure if I'm handling all of the resourced in ...
Steve's user avatar
  • 303
7 votes
1 answer
104 views

Streaming a Pin functionally(ish)

Earlier today I wrote a question (Validating a StreamingPin) and I thought it was a good idea (apparently I was the only one who thought so, but whatever), so I proceeded further with it and developed ...
Der Kommissar's user avatar
6 votes
6 answers
15k views

Validate that a given string (name) meets certain requirements

...
Muhammad Raja's user avatar
6 votes
5 answers
3k views

Take N elements from List of Lists

I've come with a solution super tricky for a simple requirement. I think I could solve the problem using LinQ, but I'm not seeing it so clearly at all. What's sure, I'm not comfortable with my code. ...
Facundo La Rocca's user avatar
6 votes
5 answers
33k views

Faster way of reading csv to grid

I have following in Windows Forms .NET 3.5 It works fine for csv with records less than 10,000 but is slower for records above 30,000. Input csv file can can any records between 1 - 1,00,000 records ...
Pratik's user avatar
  • 161

1
3 4
5
6 7
25