C# is a multi-paradigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform.

learn more… | top users | synonyms

2
votes
1answer
11 views

Simple Generic output for Deserializer

Lately I have been learning about serialization so I decided to write a little helper class for my application to make it easy to use this feature in multiple places. I actually mixed some generics in ...
1
vote
1answer
27 views

Detecting the attachment of a DataContext

In our application the views and the viewmodels are created in parallel to increase the performance and when the viewmodel is created it is attached to the datacontext. While there is no datacontext ...
2
votes
2answers
47 views

Is this a thread-safe implementation of background bitmap generation?

For a game implementation, I have a very large overview map with multiple layers (namely base-map / units / highlight & info / fov-shading) of which the first is CPU-intensive to generate. I have ...
11
votes
2answers
397 views

Reverse a sentence quickly without pointers

I am trying to reverse a sentence contained in a string and return a string in the quickest way possible using the least amount of memory. Also I don't want to use any unsafe code, so no pointers are ...
4
votes
2answers
94 views

C# static class holding list of member class instances

I was wondering if such a design was a bad idea in C#. Here I have a static class EventLog which holds a list of instances of ...
3
votes
1answer
82 views

RoundStack Implementation

I just recently made an attempt at implementing what I have been led to understand is called a RoundStack, simply meaning contrary to .NET Stack's default behavior ...
-4
votes
0answers
13 views

Way to increase the value of entries in lists? [on hold]

I have written a code where I'm rounding decimals to whole numbers and add them to a list. The program then checks the sum of those numbers against the previous sum of those numbers (before rounding). ...
6
votes
0answers
42 views

C# SHA512 Memory Issue

I need an implementation of PBKDF2 in C#. There is already a class Rfc2898DeriveBytes, but it uses SHA1, and I need SHA512. The problem that I faced with during ...
6
votes
1answer
41 views

Throttling commands

I have a scenario where my BaseRepository gets a lot of commands in a short time period. At other moments, this doesn't happen. What I want to achieve is to throttle these commands. I.e., when a ...
1
vote
1answer
41 views

Dependency Injection With Unity in MVC 5 without repository and unit of work

I want to use dependency injection with Unity in my application. I am not following repository pattern and unit-of-work (and don't want to). I also have ViewModel in my controller action method. ...
2
votes
1answer
33 views

A thread-safe initialization guard

I have written a type with the following public API: ...
3
votes
2answers
112 views

Uppercase the initial char of every string in a list

My problem is that I have a sequence, potentially infinite, of strings. Let's suppose it to be {"Mickey Mouse", "Bugs Bunny", "Winnie the Pooh"} I have to make ...
3
votes
2answers
234 views

Smartly encrypting strings

I am trying to encrypt the input string using the following rule: 1st Character of string will be increment by 4 ( a will become e ) 2nd Character of string will be increment by 1 ( a will become b ...
3
votes
2answers
60 views

Check if array A contains all elements of array B and vice versa irrespective of order

I am trying to check if an Array A contains all the elements of Array B and similarly ...
2
votes
1answer
40 views

Design patterns: choosing the right handler depending on data type

Suppose we have an application which process packets from somewhere. We should choose right handler for the packet depending on packet type and also we know that it might be necessary to change ...
6
votes
3answers
116 views

Classify values depending on predicates

I've to do a generic method Classify<T> that, given a sequence of elements of type T and an arbitrary number of ...
8
votes
5answers
811 views

Assembling a user agent descriptor, implemented using StringBuilder vs String

I think performance won't be a big issue here as the concatenation only happens once (2-3 at worse because of multiple threads). Out of the two methods, which one would you prefer, in terms of ...
3
votes
2answers
62 views

Communicating messages to objects

In my MUD game engine, I built a messaging api that allows objects to subscribe to concrete implementations of an IMessage interface. Is there anything glaringly ...
5
votes
1answer
44 views

Handle Settings in Windows App

So, I fixed my problem with a public ViewModel for my MainPage like this: MainPage.xaml.cs: ...
3
votes
3answers
92 views

SQLite insert code optimization

I just started working with SQLite in C# to test various features of an application. In building my first SQLite example I wanted to insert a large csv into a table (Person) with two columns, A and B. ...
4
votes
1answer
48 views

Class for easier to read IProgress<Class> handling

The recommended way to report something as "progress" back from a async function is to use IProgress<Type> or ...
4
votes
2answers
90 views

Query results with many to many and some parameters using Entity Framework in a more efficiënt way

I've created a working query in Entity Framework and I'm curious if there's a better way to do this. Since there's a lot of field on my models, I will only publish the relevant ones here. My Models ...
8
votes
3answers
438 views

Brute force MD5 password checker

I'm trying to create a C# brute force MD5 password checker. If I run it with "test1" without MD5, it completes in 15 seconds. I would like to make it faster, but I'm a c# beginner, and don't know how ...
1
vote
1answer
71 views

IRepository Pattern - Interface Segregation Principle

I have an IRepository class that I use a lot. But I noticed that for many of my repositories I do not implement most of the methods. Also, I usually don't have a ...
3
votes
1answer
34 views

Wiring CollectionView and grouping it without slowing it down

In my previous question, I got heaps of good advice BUT no solution for the problem apposed. I applied the valuable learnings from the past on this.question and am also hitting it from a different ...
2
votes
1answer
38 views

Solidworks save as PDF macro

This just opens all drawing files in solidworks and saves as a .pdf file. I just wanted to make sure it can't stuff anything up if I let it go on the actual drawings database (i.e. all our files) and ...
2
votes
2answers
71 views

Timecode class design

I've created a Timecode class. The "timecode" that I'm trying to represent is a timecode that is used in video editing quite often, and is seen displayed in the ...
7
votes
1answer
53 views

Refactoring my Todo List was on my Todo List. How's my MVC?

This is a follow up to Rolling my own Configuration with UI. I got a lot of great advice about the Configuration system I created, but no one touched on how all of my logic for the UI was in the code ...
10
votes
2answers
242 views

Reusable Unit Of Work Interface / Factory

Given my IUnitOfWork interface using System; public interface IUnitOfWork : IDisposable { void Commit(); } I then ...
10
votes
3answers
714 views

Lvl 1 upgradeable attributes

I've built the groundwork for an attributes (as in Strength, Intelligence, not as in DebuggerHidden, TestMethod) framework for ...
1
vote
1answer
37 views

Handling overwriting of unique Dictionary values

I am working in C# to write a scheduling application for operations in a factory. I have a custom class Workday, with properties to represent a ...
5
votes
1answer
43 views

Image cache for lots of images 2.0

Following from this question I created a Image cache of sorts (let's call it version 1.0) that used WeakReference as "cache" items. And this comes from the ...
-5
votes
1answer
57 views
4
votes
3answers
91 views

Moving business logic towards the domain object as a design pattern

My project is composed of several parts: Repositories, Services, Domain objects, etc in a .NET MVC web application. My repositories handle all data i/o, the services are responsible for CRUD ...
1
vote
1answer
44 views

Image cache for lots of images using WeakReference on C#

I'm developing an application to manage a player card-library from an online game. Each card has an image that is stored on disk with a numeric code, for example, the card with ID=1234 has his image ...
4
votes
2answers
56 views

Class to DataTable or Datatable to class mapper

My code goes from a class to DataTable, and back again. It populates the class's public properties, or creates DataColumns whose ...
3
votes
3answers
63 views

Implementing a singly LinkedList and IList interface

I have implemented a LinkedList in C#. What would you change/make better? What naming conventions are misused? What would you add? Some of my ideas are to make it ...
2
votes
3answers
263 views

Simple script to find the largest number palindrome

I have made a simple C# script that will find the largest palindrome made by the product of two numbers. These numbers will be between a minimum and maximum value, inputted by ...
5
votes
1answer
66 views

Regex for matching a US phone number

I have written my first regex: ...
4
votes
1answer
96 views

C# photo sorter

I am quite new to C#, currently working through a number of pluralSight courses. I've written a few small things here and there, but never anything that performed an entire purpose/function from ...
0
votes
0answers
36 views

Refactoring ideas wanted [closed]

I have a several WebApi controllers have that use 2 generic classes for processing. Depending on the data sent in the request, one of the generic classes is called. This logic is wrapped in a ...
-5
votes
0answers
51 views

Very bad approach to control PC (using direct link to a txt file) [closed]

I know the code is bad, and I need to know how exactly do I improve it? If you have some time to spare, please do a quick/thorough review of this thing. I would be even more happy if you commit ...
5
votes
2answers
206 views

C# approach to prevent null references in strings

My insight here is that it's usually not useful to distinguish between null and empty strings. Sometimes it is, but usually not. Usually I like to assign my strings ...
-3
votes
0answers
35 views

Abstract methods vs constructor parameters [closed]

I have a class that takes a lot of parameters, and to simplify things I created a child class that calls some static methods to retrieve those parameters (file names and the like): ...
14
votes
5answers
2k views

Linq me a FizzBuzz

I got this requirement recently: Write some code that prints out the following for a contiguous range of numbers: the number 'fizz' for numbers that are multiples of 3 'buzz' for numbers ...
2
votes
0answers
39 views

Grabbing the talking stick - aka acquiring an exclusive lease

A little bit of explanation on what I need this for: In a project that is deployed as an Azure Cloud service, I have a number of servers - some web front ends which service web requests and some ...
6
votes
3answers
103 views

Using enum descriptions to string/text binding

In my WP8 application I need to show a couple of radio buttons to let the user select a value out of an enum. I don't want to hardcode either the value or the text ...
5
votes
2answers
99 views

Project Euler #7: 10001st prime

This is my implementation of Project Euler #7. Have I overdone it again? Is there anything else I should or should not do? It runs in 9 milliseconds on my computer. What is the 10001st prime ...
3
votes
2answers
54 views

Nullable Generics - Implementing SequentialSearchST in C#

For learning purposes, I am implementing certain code from Sedgewick & Wayne's Algorithms, Fourth Edition. Because of language features, a direct translation doesn't seem possible. For example, ...
5
votes
2answers
65 views

Project Euler Attack #2

This is my implementation of Project Euler #2 in C#. It takes 0 milliseconds to run, and I believe it is correct - I have seen nothing to indicate otherwise! By considering the terms in the ...