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

-3
votes
0answers
11 views

How to write tests for legacy code and then refactor it? [on hold]

I have a project with lots of ugly code I've written some time ago. Now I'm trying to make it testable and to use TDD for further development. But every time I'm trying to write unit tests for ...
1
vote
1answer
157 views

Avoid using object to hold int, bool, double application setting values

I have some code to handle integer, double, Boolean, and string settings. Right now, each setting variant extends an abstract class, where the setting value is stored as an ...
-4
votes
0answers
18 views

What kind of setter do I need write? [on hold]

I'm new in the OOP. Please, help me. I marked some property like "obsolete", and created 2 collections. What kind of setter do I need to write in these(obsolete) properties for backward compatibility ...
2
votes
0answers
32 views

Returning IQueryable<T> from my repository in Repository pattern design pattern

I am developing an application based on Repository design pattern. What should be the return type from the Repository? This is my UserRepository class: ...
2
votes
3answers
31 views

Select the next TextBox in order

Could somebody help me out with trying to clean up this big list of if / else if statements please? I've found that switch statements won't work because it won't handle a TextBox as the parameter. ...
2
votes
4answers
222 views

Product Manager managing product listings and prices

For school we have to develop a product manager. The basic task is to add new products. A product has a name and a price. I know the one or other class is currently pretty empty but its planned to ...
0
votes
2answers
43 views

Implementation of asynchronous (?), self-refreshing cache of object collection bulk

I'm trying to create a caching solution used in various parts of a clients' application. The resulting code will be open source. For example, it will be used for caching API queries like "get all ...
-2
votes
2answers
29 views

Raise, handle and note down the custom exceptions [on hold]

I am creating a custom Exception class and trying to log the CallerFilePath, ...
4
votes
2answers
212 views

Read binary serial data and parse integers

I'm reading serial data in binary format from a stream, and I'm not happy with how I extract the data because it takes so much operations to extract the binary data from a simple line of binary data. ...
2
votes
0answers
41 views

Selection from different collection by using GroupBy

Is it possible to simplify this code? Maybe we can use linq? ...
5
votes
3answers
175 views

Generic getting single value from DB in C#

Few months ago I posted my code Getting a single value from the DB. I implemented suggested changes and this is how it looks like right now: ...
6
votes
1answer
50 views

Boilerplate singleton / lazy initialiser

I'm working with an existing code base here and while I don't have the time/budget to re-do the entire thing (ultimate solution), I do get a bit of leeway to enhance the code base, as well as ...
-2
votes
0answers
23 views

Unit Of Work and locking construct, EF and ASP.NET webforms [on hold]

I am working on an existing ASP.NET web application that uses the repository pattern and EF. In some cases, I noticed errors when saving because of for e.g. taking max value from database for code ...
-4
votes
0answers
23 views

C# I want to move to another switch (previous in this case) [on hold]

I want to get back to the previous switch when I press [1] - Move Back Also in another project I want to move from a switch to another. Is this possible? I'm totally new to this. I tried goto and ...
2
votes
1answer
44 views

Object pooling for a top down shooting game - Revision #1

After the advise from this code review I have come up with the following changes. I'll go in the same order as my previous post. This post is mainly for an updated version so that others can see the ...
8
votes
2answers
381 views

Calculator in C#

I'm pretty new to C# and was just wondering if there is a better way I can write this calculator that I made: ...
-3
votes
0answers
27 views

Generating all random maches from lists with some exceptions [on hold]

I have some lists like these to generate eyes description (for a bigger character description program) ...
4
votes
2answers
60 views

Lightweight implementation of the in-close algorithm from C++ to C# translation

The following C++ code is a lightweight implementation of in-close algorithm. Full details of the project can be found here. I was trying to translate the C++ code to C# but it's very difficult to ...
2
votes
2answers
48 views

FileSystemWatcher created event

I wrote a little function that monitors some directories. If a file gets created, it will check in the extension list for a match. Can you please tell me if I could make my function better in any way? ...
4
votes
3answers
78 views

Wordy LINQ for XML word list

This code works as intended, however, I am sure that there is a way to condense the xmldataLoad method. If someone could maybe explain a better approach than what I ...
4
votes
2answers
82 views

Rational number implementation

I've been recently working on a custom rational number implementation. Due to not very interesting reasons, using this implementation is not an option. I'd appreciate comments of anyone who has the ...
3
votes
4answers
236 views

Equals method for a class representing an origin and destination

Have I over-ridden GetHashCode properly in the below code? ...
1
vote
1answer
55 views

Table join using the repository pattern

I am new to repository pattern. If I want to join two tables, where should I implement the logic? I have implemented it as shown below. Is there any better way to achieve the same? This is my ...
-1
votes
0answers
39 views

Reuse code in unit tests

Currently we are trying to implement some unit testing on our services. In the below service an order is created and a audit registration is made about the creation of an order. When writing the two ...
5
votes
0answers
30 views

Using delegates to avoid duplicate creation of resources

I'm writing a PCL that uses an HttpClient to go visit a few sites and extract data from them. My initial code looked like this: ...
11
votes
7answers
845 views

Scoring a Scrabble Word

I was asked before an interview to create a console application that will work out the score of a word for the board game scrabble. It worked fine but the feedback I received said: "there were no ...
3
votes
2answers
35 views

MVC-Web API 2 integration

For the first time ever, I'm integrating an MVC website to an ASP.NET Web API 2 web service (both of which are coded by myself). I'd appreciate it if you can just look this over for me and let me ...
6
votes
5answers
276 views

“Critter Tracking: When does it cross its own path?” Part 2

Basic Info: This question is my second attempt at this question. It is based on a question similar to this Codility question. The input (an int array), the outpout (an integer) and the method ...
6
votes
1answer
69 views

Shuffling an arbitrary list or sequence

After reading this question I wanted to write a short example of how a list or sequence could be shuffled in .net. The result turned out to not be very short: Program.cs ...
4
votes
1answer
72 views

Object pooling for a top down shooting game

I have an Asteroids clone I'm working on and I want to see if my object pooling is written correctly. The code works I just want to know if there is anything else I need to change to make it more ...
4
votes
1answer
51 views

Unit testing a CharGrid

I wrote NUnit tests for class CharGrid from this homework assignment. My goal here is DRY: I want to keep the testing code as short and simple as possible. In addition, want to run every test ...
2
votes
0answers
33 views

DataDictionary Application - Controller

This is related to DataDictionary Application - Model I haven't done much on the controllers yet, as it's the first time I've written Controller-type classes and wanted some quick feedback on really ...
2
votes
1answer
47 views

DataDictionary Application - Model

Following on from my previous question, I think my Entity Framework model code is now complete. First I'll provide a quick overview of the program - everything above the next horizontal rule can be ...
7
votes
3answers
318 views

Comparing two objects having two nullable date fields

ExpiryDates has two properties PSL_ExpiryDate and MNL_ExpiryDate of type nullable date. I am ...
6
votes
4answers
96 views

Efficient random code generator

I made a 16 character code generator. It works like a charm now, but I was wondering if there's any way to do it more efficiently. ...
1
vote
2answers
32 views

Basic survey app

I am learning MVC 5 .NET and this is a bit different than Rails activerecord when creating relations. I have created a basic survey app that has a Survey class and this relates to the questions and ...
0
votes
1answer
33 views

Separate business logic from Data Access Logic in the repository

I have a PupilService which is calling the PupilRepository.AttachPupil() method. I have an N to M relation between ...
11
votes
2answers
135 views
+100

Abstract syntax tree for simple Lisp-like interpreter

A week or so ago, I wrote a binary expression calculator with the hope of better understanding how interpreters and compilers work. In the same vein, I've tried to write a lisp like language ...
13
votes
7answers
1k views

Imposing a sort order on a query

I've always been told "never use goto, there's always a better way" and for the longest time I just accepted it. Lately though, I've been running into such scenarios in which I have to repeat this bit ...
5
votes
3answers
109 views

“Critter Tracking: When does it cross its own path?”

Added: Version #2 of this question Minor Update/Additonal information: This question is based on a Codility question similar to this one. The input (an int array), the outpout (an integer) and the ...
4
votes
1answer
73 views

Attribute container

I made this really simple "attribute container" class that allows you to store arbitrary data to an object at will, sorta like in python how you can just assign attributes to arbitrary objects, but in ...
1
vote
1answer
35 views

Interface for fixed-size container supporting max, min, sum

I had posted this previously as part of Generic container similar supporting PeekMax, PeekMin, Sum, and PeekNextToMax but I think it was to big a morsel for people to chew on. So I'm splitting it up. ...
2
votes
1answer
67 views

Pattern for creating objects and set their common base and specific derived class properties

I have a scenario to design a class structure to creates different types of derived class objects and set some of their common base class properties. Here is the final pattern I came up with to solve ...
1
vote
1answer
72 views

Naming request for a class to return a different value every so often

I have a class that I'm trying to determine a good name for. I don't know if this concept comes up a lot in programming or not, but I'm wondering if I can get some suggestions for a good name for the ...
3
votes
4answers
477 views

Copy autodiscovery results from list to an array

I copy addresses from the endpoints to an array that should only hold the endpoint addresses. This works but it seems so old school :/ Can I make this faster, better, more sexy (LINQ)? ...
2
votes
1answer
60 views

MVC Repository Insert Using async

This is practically my first time using async in my code. I read about dos-and-donts but I wanted to get some feedback on what I've written. I'm using a repository ...
2
votes
0answers
32 views

N-Layer using MEF dependency injection on MVC project

I'm trying to create a "perfect" generic solution structure for MVC (5.2.3.0) projects using MEF. Currently my solution looks like this. Core layer contains generic classes that could be used in ...
3
votes
1answer
45 views

Binding Lists to a DataGridView in Winforms

I'm using Winforms and I find this pattern showing up in my code a lot. It works, but I'm unsure if it's best. The goal is to pass an IList of items through a view ...
4
votes
2answers
79 views

Get an integer as input and display Pi rounded to that amount of decimal places

I've been writing a program that accepts an integer as input and displays the number Pi rounded to that number. The only issue I see is the fact that the Math.Round ...
2
votes
1answer
48 views

Testing that a class with a lot of data is inserted into a repository

I have a legacy system with a class with a lot of data. I am creating a web service that inserts a new claimant into that system for a contractor. I can not refactor the claimant object. I need help ...