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

Benchmarking things in C#

I needed a better way to benchmark code, because, well, rewriting the same benchmarking code every time I need it is just...well...unpleasant. So, here's a class which does just that, it runs an <...
38
votes
3answers
10k views

Exporting doc types using queues and multithreading

For a while I have been interested in seeing if some tasks work well when split across multiple threads. On the one project I have been busy with I have been creating a lot of small utility apps, to ...
33
votes
6answers
4k views

DisposableObject base class for C#

I commonly run into the need to implement IDisposable in my code. To correctly dispose of both managed and unmanaged resources requires a reasonable amount of boilerplate code. Based on the ...
32
votes
3answers
47k views

Entity framework with repository and Unit Of Work pattern and POCO architecture

This is my architecture to EF4 using repository pattern and unit of work pattern with POCO. I believe I made some mistakes. I have a solution with 5 projects: ...
28
votes
6answers
3k views

Extensible code to support different HR rules

Recently, I got challenged to code with following bullet points: Extensible code to support different annual leave rules for HR departments Maintainable code to add/change the existing rules ...
26
votes
1answer
6k views

Fluent LinkedIn REST API client interface design

There is a handful of LinkedIn clients written in C# on the NuGet package library, but as far as I can tell, most only do authentication via LinkedIn. I found a couple which offer a LinkedIn REST API ...
24
votes
2answers
12k views

Reusable Unit Of Work Interface / Factory

Given my IUnitOfWork interface using System; public interface IUnitOfWork : IDisposable { void Commit(); } I then ...
23
votes
2answers
121k views

Implementing a good TCP Socket Server

I'd like a code review on my very simple server application that validates whether the serial number retrieved from the client is a valid one or not. Is there a better way to handle the start/stop ...
23
votes
5answers
15k views

Best way to pass parameters to Factory class?

So I have a series of objects, which I will call Impl1, Impl2, and Impl3. They each implement an interface, called IImpl. I have a Factory class who's task is to retrieve the ImplX which is ...
22
votes
4answers
37k 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 ...
20
votes
3answers
16k views

Determining if a connection has been made to a communications device

I am unsure if my use of Monitor.Wait and Monitor.Pulse is correct. It seems to work alright, but there is a nagging doubt I am ...
18
votes
8answers
2k views

Counting elements meeting a predicate in an enumerable without iterating the entire sequence

I was reading this question, and the answer that mentioned streams, and a thought had occurred to me. In many cases (at least in my usage) I want to determine if a sequence (or ...
18
votes
2answers
92k views

Displaying data from a database onto a form

I'm a beginner to .NET and could you guide me to right direction. My problem is based on the following code. Here I have 4 variations of same method and all 4 variations are working fine. What is the ...
17
votes
2answers
35k 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. ...
17
votes
2answers
15k views

Secure password hashing

I have found a password hashing article and an implementation. Is this code secure if I increase the salt to 64 bytes, hash key size to 128 bytes and the iterations to 10000? Are there ...
17
votes
3answers
8k views

scoped_ptr for C++/CLI (ensure managed object properly frees owned native object)

Motivating SO question: Is there a C++/CLI smart pointer project (e.g. scoped_ptr)? I'm interested in any reviewer comments, and especially identified bugs or inconsistencies with the native ...
16
votes
5answers
2k views

Populating a ListView with Items

I populate a ListView with Items. Each Item has data attached to its .Tag property. Over time, I have needed to handle many cases where something would be null or ...
16
votes
2answers
848 views

Enforcing string validity with the C# type system

One of my biggest complaints about .NET is that there's no way to guarantee a string match a certain type in the type-system. Note This started as more of a proof-of-concept than a real usable ...
15
votes
6answers
14k views

Determine if an image is opaque or transparent

I wrote an extension method defined for the Image Class (System.Drawing) — which returns a Boolean value telling you if the image is opaque or transparent. The color of each pixel in the image is ...
15
votes
4answers
533 views

Entities and the things they do

So I have an Entity, which is responsible for providing an abstract base for other objects to inherit. (Like Actor objects, ...
15
votes
4answers
1k views

Is decoupling necessary for very small applications?

I threw together a small solution for my organization today for some basic data review and approval procedures. This particular application will likely not change or add functionality at any time. ...
15
votes
3answers
8k views

Change desktop background

I've created a simple program that downloads an image (different image every day), then sets it as my desktop background. It is a console application, and closes immediately after downloading the ...
15
votes
3answers
2k views

Simple Linked List

I've implemented a simple linked list in C# using generic T for values. I did not inherit from any of .Net's fun and helpful classes like ...
15
votes
5answers
24k views

Finding elements inside ExpandoObject

Is it possible to simplify the code below? ...
15
votes
2answers
10k views

Guitar Hero III Bot

I made a Guitar Hero III bot for PC. I was able to beat the song "Through the Fire and Flames" on Expert with the bot which can you see here. If you watched the video, you can see that the bot misses ...
14
votes
6answers
3k views

Showing various network information from a NIC card

I have included the code from a second year project that I would like some advice on. Basically it utilises WMI to query a NIC card from a selection (depending how many are installed in the host ...
14
votes
7answers
1k views

Binary Heap where a comparison delegate is used

I currently have a Generic Implementation of a BinaryHeap. It must be able to maintain it's integrity with elements that may or may not implement ...
14
votes
5answers
1k views

Reusable implementation of IComparable<T>

I often find myself implementing IComparable{T} in different classes for sorting in a very similar fashion: Values meeting criteria X and Y should be sorted to ...
14
votes
9answers
1k views

How can I refactor to avoid repetition finding the index of strings in a list?

I have a list of strings where I want to find the index of a first- and second-choice video compressor. Logic: If the first choice is available, return its index. If not, and the second choice is ...
14
votes
3answers
21k views

Building a Tree from a flat List<Nodes>

This is my incoming data: ...
14
votes
4answers
2k views

Making a web service call based on a type of request

I have my code which makes a web service call based on a type of request: ...
14
votes
3answers
24k views

Convert string to multiline text

I made this method that takes any string and transforms it into a multiline text l; each line having the max (character) length specified by the rowLength parameter....
14
votes
3answers
14k views

Design pattern for implementing multiple data sources

I've written a program to populate a particular object from multiple data sources, however I'm not convinced I'm going about this in the right way: I have no idea which (if any) design pattern I have ...
14
votes
3answers
18k views

Timing out a method

I have created this extension method that can be used to run a function with a timeout applied to it. Is this a sensible way of doing it? ...
13
votes
7answers
41k views

Regex validation for Email Address

I need to validate whether my regex is correct for below scenario. Suggestion's if the regex is correct: Wiki Link Local_part The local-part of the email address may use any of these ASCII ...
13
votes
3answers
4k views

What do you think of this improvement of Linq's GroupBy method?

Linq already has a set of GroupBy methods for enumerable, which returns IEnumerable<IGrouping<TKey, TSource>>. I dislike this return type because it ...
13
votes
6answers
1k views

Form to create new students or view existing student information

I started out with the best of intentions, but this form got hacky real fast. It's purpose is to serve as a create new Student form. Also, if you want to view an existing Students information. Think ...
13
votes
5answers
13k views

Is this Repository Design Pattern Valid and efficient?

I am using Dapper ORM in my Data access Layer, but I think analysis of the code below doesn't depend upon any specific ORM. What should be the single common place throughout the entire Data Access ...
13
votes
1answer
34k views

Method that returns description attribute of enum value

I have the following method in .NET Core that returns the description attribute of an enum value. I think this code can be more elegant. I'd appreciate some ...
13
votes
4answers
338 views

Lines, intersections and terrible unit tests

I needed Line and LineF for the next stage of a project I'm working on, so I developed them. I also needed to determine if two ...
13
votes
2answers
13k views

Listing the weeks in a given month

I need to take a month (defined as a start and end date) and return a set of date ranges for each week in that month. A week is defined as Sunday through Saturday. A good way to visualize it is if ...
13
votes
1answer
470 views

.NET 4.5 licensing subsystem using RSA-4096 strong name key, SHA256 signed XML, and assembly signature enforcing

Abstract For the past week I have been looking at taking advantage of the .NET 4.5 improvements to code signing and XML signing to produce a licensing subsystem I can use to license my own products. ...
12
votes
3answers
8k views

Extension method replacing elements from an IEnumerable<T> collection

Today I needed a method to replace all 'x' values in a said collection. Since there is no such method by default in .NET I wrote my own: ...
12
votes
3answers
8k views

Function to find a certificate in either the user or the machine store

I wanted a function that would return a certificate, given its serial number, regardless of which store it is in. It has to do almost the same exact thing but twice (once for each store). To keep it ...
12
votes
2answers
565 views

Attempt at a sorting algorithm

I've been playing around and reading up on some sorting algorithms, and I've decided to try writing my own. It turned out to be quite fast (compared to the others shown in the image below). I'm very ...
12
votes
3answers
471 views

Key Order Agnostic, 2D Dictionary

Note: I am using Unity3D game engine, which uses .Net 2.0 (.Net 2.0.50727.1433 to be precise) to compile code, so I don't have access to newest features of C# 6, or even C# 5. Please keep this in ...
12
votes
4answers
43k views

Test connection to database C#

I've created a small method to test the connection to a database: ...
12
votes
1answer
592 views

Utility functions for supporting memoization for functions

I've got a couple of utility functions to support memoization for functions with anywhere between 0 to 8 arguments: ...
12
votes
1answer
1k views

CultureInfo with fallback routing to another language

Our company needs a localization/translation behavior which allows incomplete (ResX) resources. If a String isn't available in italian fall back to the next roman language, like french fall back to ...
12
votes
2answers
1k views

Implementing Dynamic Network Message Handling

I'm trying to handle network messages in a dynamic, and effective way, though I feel I've overthought it again. As of now, I have a very structured approach, but it feels as if it's a lot of overhead ...