The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
10
votes
1answer
14k views

Using System.Security.Cryptography.ProtectedData, do you see any issue with encryption and encoding?

The application needs to keep a secret which is known to logged in windows user. User enters secret in windows form's text box which is read by application. This is in form of ...
10
votes
2answers
1k views

JSON parser in C#

I've writen a C# JSON parser, but its performance is not as good as JSON.NET. Running the same test, my parser takes 278 ms and JSON.NET takes 24 ms. What should I do to optimize it? It seems that ...
10
votes
1answer
2k views

Fast bicubic upscaling in C# for image scaling

I've been trying to write an image scaler in C# with a focus on improved performance over the GDI+ scaler. My current bicubic implementation when running with a single thread is slightly slower than ...
9
votes
2answers
27k views

Replace each whitespace in a string with “%20”

My implementation: ...
9
votes
5answers
48k views

Transaction handling for multiple SQL statements

In this code I update two tables called Payment and SalaryTrans. First I insert records (Salary payments) to ...
9
votes
6answers
5k views

Loop months between a time span yyyy-mm and yyyy-mm

I'm trying to come up with a more elegant solution for a loop in months that I wrote long time ago in C# 1.1 I use a helper class Month but I'd prefer to get rid of it and make the code shorter and ...
9
votes
5answers
5k views

Multiple 'using' statements in method implementation

I'm learning WebAPI framework for ASP.NET and C#. Is the following way of handling incoming data correct? ...
9
votes
5answers
13k views

Function for determining triangle type

A while back I was asked to write some sample code for a job that I was applying for. They wanted a class that had a function that would accept three lengths and return the appropriate type of ...
9
votes
4answers
36k views

Converting the DateTime to and from Unix epoch times

I'm currently working on a thing I needed this feature for. Essentially, these are two methods to convert DateTime objects to and from the Unix epoch time (two ...
9
votes
3answers
5k views

Take previous element from array if condition on current element matches

Any ideas to simplify this beauty; I would prefer a LinQ expression if possible: ...
9
votes
2answers
27k views

C# AES Encryption

I've been researching AES encryption a bit over the past several days. The official (MSDN) examples I've seen are encrypting and decrypting using the same AES instance. They don't go in to what to do ...
9
votes
3answers
560 views

LINQ-ifying Colour Generation from Strings

Recently I was thinking about how Google, Microsoft Outlook on Windows Phone (and now many others) method of giving you a coloured icon with a letter in the centre of it works. Essentially, given ...
9
votes
3answers
787 views

Making sure initialization code is executed before other code using Lazy Initialization

The Problem Recently I was told to refactor i.e. move some initialization logic from the constructor. I came up with something similar to the posted code. In actual there are bunch of loader classes ...
9
votes
3answers
15k views

Collection that can be modified in a foreach

Sometimes you want to add/remove items from a collection inside of a foreach loop. Since this isn't possible, a common pattern is to add the items to a separate ...
9
votes
2answers
53k views

Update multiple records with Entity Framwork

I am wondering what the best way to update multiple records with Entity Framework is. This is how I normally do it, and it does work: ...
9
votes
1answer
3k views

Database Class Creator

Overview I've written a class that will create C# code. The output is a single .cs file for each table in the default database (the database is defined inside a web.config file). I'm looking for a ...
9
votes
2answers
21k views

User Password Encryption in C#

I am maintaining an old codebase of one of our legacy .Net applications which has a component that encrypts and decrypts user passwords using symmetric key cryptography. Since cryptography is not my ...
9
votes
2answers
475 views

Responding to API requests with much complexity

So having used the SE API multiple times, I like how all responses are in a Wrapper object, and for my own API design I figured it was a good method to follow. Of ...
9
votes
2answers
943 views

Helper class for Null and Empty checks

I have some static helper class: ...
9
votes
2answers
2k views

Non-blocking, non-threaded HTTP client implementation

This is a C# WinForms program targeting .Net 4.5. I am using it for a movie organizer application that will contact sites like OMDB, MyApiFilms, etc. for data about the movies. At the main application ...
9
votes
2answers
3k views

Monitoring the clipboard

The following class monitors the clipboard and raises an event whenever the contents change. The monitoring starts when the class is created and ends when Dispose ...
9
votes
2answers
3k views

Async Task implementation

Beeing on .NET 3.5 i don't have access to the TPL. Yet i have become fed up of having to manage manually the logic behind delegate.BeginInvoke type of scenarios each time and i set up to implement my ...
9
votes
1answer
463 views

A Covariant Tuple

I was searching for a way to put a Tuple<List> into a Tuple<IEnumerable>, and I found that Tuple has no covariance. ...
9
votes
2answers
443 views

Dynamic network messaging

I'm building a client and server for a game but wanted a generic messaging system in a shared library that let me focus on application logic and was largely separate form the underlying networking I/O ...
9
votes
1answer
2k views

ResettableLazy<T>: a resettable version of .NET Lazy<T>

I implemented a resettable version of .NET Lazy (context: mostly to use it in a MemoryCache for auto refresh purposes on item expiration) This is a very naive implementation and I am pretty sure ...
8
votes
7answers
1k views

Refactoring a bunch of and statements

Trying to refactor this code and can't seem to think of a way to make it cleaner. Type is a property in my Person class. ...
8
votes
3answers
16k views

Throwing exceptions when validation fails

When I want to check the validity of an attendance being entered into the system, I perform following action. AttendancePresenter Class ...
8
votes
3answers
5k views

Format a timespan with up to two fields

I'm looking to achieve a time format that looks like this: 2d 4h remaining; or 1h 36m remaining; or 35s remaining, etc. So that it only displays the two largest values of time (this is how Clash of ...
8
votes
2answers
5k views

Replace all the occurrence of a string

I have the following function to replace all the occurrence of a string that matches certain token. ...
8
votes
2answers
6k views

Copy a similar list to another

My code works fine and I am just wondering is there a more efficient way to copy a similar list to another and ignore the properties which are not present. ...
8
votes
3answers
484 views

Return a key when a function returns true

I've no idea what to call this, so I called it Classify since that's how I use it. Basically, the idea is to pass a ...
8
votes
5answers
2k views

Removing exact instances of elements in one list from another

Basically, here's the problem statement: Given an IEnumerable<T> source and an IEnumerable<T> exceptions, return ...
8
votes
2answers
134 views

Non-Entity framework database interaction model

A C# WPF user interface has been developed for the Book Inventory MySQL database previously shown in this question. Since the database had already been developed this was a database first ...
8
votes
1answer
4k views

Concurrent HashSet

I've recently been using HashSet and locking on each method, I found this to not only be a lot of work (was using it in a lot of places) but I started to see inconsistency in my code. I later decided ...
8
votes
2answers
1k views

ROT13 encoder/decoder

This is a simple utility, intended to sit on the desktop for when needed, that does the simple ROT13 encoding and decoding. I am used to coding in VBA, and I am interested in more .Net idiomatic ...
8
votes
2answers
139 views

Let's do some “enciph5r47g”

I implemented the enciphering/deciphering algorithm from this code golf task. Enciphering reads string from left to right, replacing each character by a number N (0-9) to indicate that it is the same ...
8
votes
3answers
186 views

RPSLS refactored to Object Oriented

I wrote a couple reviews for this CR post. In my most recent review, I refactored @Malachi 's code to fit OO design. I'm looking for any advice/hints/criticisms on it. A review is welcome for both ...
8
votes
4answers
268 views

Maximize profit on a trade route

Fixed trade route with goods and prices and fixed cargo capacity. How can I optimize profit? No cost to trade or transport - just fixed capacity, route, and prices. All products use the same ...
8
votes
2answers
5k views

Color-coded console output

I wrote this Console.Write function to use in my applications where I need to easily color-code output. Example syntax would be: ...
8
votes
3answers
4k views

Generate cryptographically secure random numbers in a specific range

A project I'm working on requires generating a random number of \$N\$ length to a very high degree of fair distribution between digits \$[0, 9]\$. That said, I used the ...
8
votes
6answers
15k views

Loop for periodic processing in a background thread

Occasionally I need to implement periodic checks in a loop in a background thread, a typical example being asynchronous processing using a message queue. While it’s not terribly complicated, I wonder ...
8
votes
3answers
888 views

Wrapping COM objects with IDisposable

One of the things believed to contribute to destabilizing Rubberduck 2.x, is the fact that a lot of COM object references are stored in many places, and ...
8
votes
2answers
628 views

Yield statement in a using block from a clarity point of view

I want an opinion of the community about readability and maintainability of the following code. This is quite a rare case when yield statement included in a using construction. I know that this code ...
8
votes
3answers
112 views

Representing and handling Data Sizes

In a very specific application I have, I needed the ability to easily convert between different data sizes. I.e. when I give an input of 1,048,576KiB, I needed it to say 1GiB, etc. So, I built a <...
8
votes
3answers
675 views

MIST - auto-implemented, attribute-driven .NET notification mechanism

I have a component that I've used myself for quite some time, the short story is that it automagically implements a property change notification mechanism (very useful for implementing ...
8
votes
2answers
2k views

Simplification of byte array comparison algorithm

I have an algorithm that evaluates in input byte[] with a source byte[]. Several conditions can be encountered: Match found No ...
8
votes
2answers
345 views

WeakCollection<T> class

Occasionally I have need for a collection of objects in which each object is referenced "weakly" (meaning the GC is allowed to collect it even when the object is in the collection). Traditionally, I ...
8
votes
1answer
16k views

Implementing IList<T>, IList & INotifyCollectionChanged

I posted this question over at Stackoverflow, which was off-topic. I was using ObservableCollection in a number of places in my WPF application for very large ...
8
votes
1answer
852 views

MVP Passive-View

First of all, I'm really new to the MVP design pattern (Passive-View) and I've been trying to implement it in a WinForms application. Before I'm going any further, I'd be very happy if you guys can ...
8
votes
1answer
3k views

Fluent Nhibernate

I'm very new to NHibernate and DB. I have three tables which are connected with many to many relationship. Here are the tables creation Script: ...