C# is a multi-paradigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform.
2
votes
2answers
64 views
Returning status codes from business layer
This is what I've been doing so far in my business layer to return error messages to the user.
...
0
votes
0answers
27 views
Open Closed Principle for IF-ELSE [on hold]
In the future there is a good chance that I will need to support another database like mySQL. How to make this code open to extension, but closed to modification?
...
3
votes
3answers
215 views
Parsing and formatting a time two ways (perfectionistic approach)
I'm still not satisfied by the readability of the code. The wanted behavior which would be self descriptive would sound like: "I've two fields; one is for the date and one for the hour. This two ...
-2
votes
0answers
25 views
Why is my random not getting the last character? [on hold]
I am trying to create a console application which is basically a very simple version of a security measure used by some websites and banks etc.
The user will have declared a "Secret Word", after ...
3
votes
0answers
48 views
Find the number of Colleges offering Combinations of Levels: Performance
I have been using entity framework 5 as DataAccess layer for my application.
I have a case where there are a set of 'Levels' offered. And I have a set of 'Colleges' offering the 'Levels'.
Class Level:
...
1
vote
2answers
78 views
“Nice Angles” - Code Eval challenge
Out of fun, I solved "Nice Angles" challenge on CodeEval in C# 4.0:
CHALLENGE DESCRIPTION:
Write a program that outputs the value of angle, reducing its
fractional part to minutes and ...
4
votes
2answers
83 views
Loading data into a number of different typed List<T>s: Can I do without reflection?
I'm not sure whether my distaste for reflection is justified or not, but it feels ucky that I'm using reflection here.
I'm trying to make a very simple class which has a number of ...
5
votes
1answer
48 views
Programming Principles - Reading/writing from/to a Mifare card
Consider the following class (I've stripped XML doc for the sake of simplicity), which does several and slightly different operations through a serial port to read/write from/to a Mifare card. It has ...
1
vote
1answer
31 views
Admin class for monitoring blog users
I have an admin class that controls when a user logs in and creates a new blog post. I am wondering if there is anything I can do to improve this class. Is there any way to reduce the code? Is there ...
0
votes
0answers
10 views
Is it wrong way to dispose CrystalReport objects? [on hold]
I am creating report files and exporting these as pdf. And I am disposing streams and report documents at the end. But, always some .rpt files are staying in Temp folder and I can't delete them. After ...
5
votes
2answers
50 views
Determining vehicle jump landing quality
I am writing a game where a car drives and makes jumps. When a jump is landed, the player is rewarded if they land all four wheels either at the same time, or near to the same time. If they don't, ...
3
votes
1answer
25 views
Design of colour fading for WinForms controls effect
I wrote this little piece of code to linearly interpolate between a winforms control's background colour and any arbirtrarly chosen colour.
I don't like the way I wrote this piece and I was ...
1
vote
4answers
69 views
1
vote
0answers
16 views
XML data-parsing design that doesn't sacrifice efficiency [on hold]
I have the following method signature
...
10
votes
2answers
228 views
Application please send me an E-mail
This is an E-mailer class that I created to send me E-mail when/if the Windows service (that will be installed on computers all over) throws an error, so that I know what is going on.
I use a similar ...
0
votes
2answers
34 views
Single responsibility principle and tasks which perform multiple related functions [on hold]
I have a task which will perform 3 main sub-tasks:
Download an Xml file.
Parse Xml file and import nodes in database.
Send a status email about completion.
I was thinking about naming the method ...
5
votes
1answer
87 views
Optimizing FirstOrDefault
I'm working on an application in which it takes quite a bit of time to initialize the data.
Some background: I'm creating a sort of pivot table in which I turn Figure 1 below into Figure 2. I've ...
4
votes
0answers
41 views
8
votes
2answers
73 views
Fixing double arithmetic errors
I am trying to account for the errors in double arithmetic in a C# program I am writing, and came up with this first solution that seems to work well for most cases:
...
-2
votes
0answers
29 views
8
votes
1answer
53 views
Compare the index of each char in a string in an alphabet array to a range of numbers
I saw this codegolf challenge and I set out to try and write a solution for it. I'm nowhere near an expert codegolfer (or programmer), but it was an interesting exercise.
Now I'm wondering how to ...
4
votes
3answers
40 views
Dataset Copy, Change, then Write new Rows back
I have this code, but I think it is too clumsy. It feels like a 12 point turn, is there a way to optimize it?
Please note that this generates new rows from existing rows.
...
0
votes
0answers
19 views
8
votes
3answers
81 views
Validation check and code-saving
I have the ubiquitous "validate and save" scenario, wherein the Save() method performs various validity checks and proceeds to save the data. The solution works ...
-4
votes
0answers
30 views
25
votes
3answers
923 views
Voxel World Optimization
This is not related to a Minecraft clone.
I am currently writing a turn-based strategy game like Final Fantasy Tactics. The game is played on floating voxel-style islands, which are generated from ...
7
votes
4answers
156 views
Memory usage in Reversi board state
I'm coding a Reversi game, with an artificial intelligence using the MinMax as the search algorithm. My concern is that (most) search algorithms needs to store a lot of instances of "states", in my ...
3
votes
0answers
33 views
Properly using parameterized Factory.Create() method using DI
My factory is using method injection because I thought this was the best way to make it so far. Besides, I doubt it is a good thing after having to call on its ...
6
votes
3answers
345 views
Count PDF pages in constructor
I have an object that represents a PDF file. In the constructor, I pull out various information about the file name and make it available via properties:
...
0
votes
0answers
10 views
Shall the Presenter depends on the View, or the contrary, in MVP? [migrated]
So far, I have used the MVP architecture pattern a few times. Every now and then, I wonder whether my Presenter shall depends on my ...
5
votes
4answers
165 views
Managing a cruise system
This program organise cruises in which it sets up the ship with cabins/rooms. It also does reservations with customer information and the cost for available cabins/rooms.
This is my main class # ...
2
votes
2answers
158 views
How far should I go with abstraction?
I've been trying for a while to write clean and testable code, with the help of DI and abstractions.
I found myself guilty of service-itis, creating 3 or 4 interfaces for something that clearly ...
0
votes
1answer
24 views
Handle concurrent HTTP requests with a generic .ashx
I have created a .ashx file that is able to handle concurrent http requests.
Works great, but now I'd like to create a base class that does the common work in order to not repeat myself each time I ...
1
vote
3answers
92 views
CodeChef Matrix Rotation
I am new to C# and have tried to solve a problem statement from CodeChef:
Problem statement
You are given an array A of N integers. You are to fulfill M queries.
Each query has one of the ...
5
votes
2answers
181 views
Applying different filters within loops
What I have is an outer loop which loops through a list of strings, followed by another loop which loops through a list of filters; and if the current column is the current filter in the list of ...
4
votes
3answers
237 views
Parsing dates from a webpage
I have two inputs (TextBox) on my front end.
The following code parses them from their string representation to aDateTime object. If it fails, it then sets ...
0
votes
0answers
11 views
Allow entities owned by a certain user to be referenced by other users' entities [closed]
I am working on an Asp.NET MVC web application.
I'm designing the entities and have become stuck in a thought rut with no other developers around to get me out of it...
I have the following ...
7
votes
5answers
2k views
One-shot events in C#
I have a class that performs some long-running operation.
This class exposes a Completed event. I'd like clients that use this class to register to get notified ONLY ONCE when the class completes ...
1
vote
0answers
43 views
Separation of concerns for security checks
I needed a nice typesafe way to implement security checks for various domain objects and actions that can be performed on them.
I had an idea how to do it, so I implemented it as a simple proof of ...
6
votes
3answers
283 views
Leaving out the max value in an Enumeration
This is part of a school assignment and I came up with the following solution to leave out the max value in a Enumeration:
...
1
vote
0answers
20 views
Liskov Substitution and SRP Principle violation - how best to structure this scenario? [closed]
While learning SRP and LSP, I'm trying to improve the design of my code to comply best with both of these principles. I have an employee class that has a calculatePay method on it. Firstly, I believe ...
7
votes
2answers
171 views
Add or view pattern with MVVM
I have a model called WorkOrder which I want to be able to manage from a single window.
The required operations (for now) are only Insert and view, so this is what ...
2
votes
1answer
35 views
Compare 2 dynamic jagged arrays of doubles and arrays of doubles
I want to be able to compare 2 jagged arrays of doubles for value equality. The arrays can have any number of dimensions. Inside any dimension could also be another array etc.
It is known that the ...
6
votes
2answers
426 views
Sieve of Eratosthenes implementation is running slowly
I have written this code to find prime numbers, and it works well, but the calculation speeds are incredibly slow. Am I doing this wrong? I know that I might be really doing this the wrong way, but ...
4
votes
1answer
33 views
Creating a set of buffers for tiles
I am currently converting a 2D game to 3D, never having worked with 3D before I am trying to learn as I go. I am wondering what the best way to use vertex/index buffers is.
I am currently looping ...
4
votes
3answers
89 views
An approach to the network messaging service
I'm working on the communication module of an ecommerce application. This module takes care of handling messages that come from other apps over the wire.
The awful switch case is never an option so I ...
3
votes
2answers
136 views
Abstract session value manager
I've been working in C# for a while, but I'm just recently starting to force myself to use better abstracted and generic code. I recently encountered a situation where I was juggling a lot of session ...
4
votes
1answer
100 views
Creating Thread safe list using Lock object
Will this code qualify for a truly thread safe list? It is using the Lock object.
...
1
vote
1answer
57 views
Creating Thread Safe or Concurrent List [closed]
Can a thread safe or concurrent list be created using the code mentioned underneath, where I wrap all the calls to the base class in a ReaderWriter lock. I can similarly implement all the public ...
11
votes
2answers
116 views
CSV reader using StreamReader and LINQ
Mostly due to readability, I am using the following code to
find a specific csv file on a drive
read that CSV file using a streamReader
parse it into a ...