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
1answer
30 views

n-layered application structure in asp.net mvc

I've been trying to set up an n-layered application in ASP.NET MVC 5. I've "converted" my account controller to look like this. I would like some feedback as to whether this is in the right ...
7
votes
2answers
84 views

SQL service broker and threading

Basically my code waits for database table a to have an XML string inserted into it. The SQL query parses the XML string and stores it into separate columns (this ...
0
votes
0answers
11 views

Cascaded DDL “Default Select List” [on hold]

I'll start by saying ddlDivision is cascaded from ddlLeague ...
-2
votes
0answers
27 views

calculate the count about C# [on hold]

I use Hashtable and arraylist put into some information Now I can get some information (just like output) ...
4
votes
1answer
62 views

Returning a list of income for a month

My current code takes 2.7-4.5 seconds to complete, is there any way to make it faster? I need to return a list of the income in all days in a month. My idea was to loop through the days of one ...
2
votes
1answer
45 views
5
votes
1answer
70 views

Extension methods for Daylight Savings Time dates

Just wondering if anyone had any suggestions for improvements. I created these extension methods so it's easier to get the start and end dates of Daylight Savings Time from the ...
3
votes
1answer
45 views

Optimizing recursive reading of a UI configuration file

In our project(windows app, winforms) the UI is designed based on XML configuration file. I have a program to read the UI configuration file and Parse the configuration and design the UI. The ...
2
votes
1answer
40 views

LINQ query using StartsWith and Contains to limit the results for an autocomplete field

As a source for a jquery-ui autocomplete field, I've written this action: ...
1
vote
2answers
65 views

Optimized code for class derived from List

I need a best optimized code for the below class to increase the performance of searching data. ...
10
votes
3answers
610 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. ...
3
votes
3answers
303 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
29 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
63 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: ...
2
votes
2answers
95 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
92 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
55 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
39 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
12 views

Is it wrong way to dispose CrystalReport objects? [closed]

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
56 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
34 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
81 views

Find out max duplicate number between 1 to N numbers

How can I make this method better? ...
1
vote
0answers
17 views

XML data-parsing design that doesn't sacrifice efficiency [closed]

I have the following method signature ...
10
votes
2answers
246 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
35 views

Single responsibility principle and tasks which perform multiple related functions [closed]

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
90 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
46 views
8
votes
2answers
77 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: ...
0
votes
1answer
72 views

Simple Dal for Accessing Procedures

How could I improve this code? ...
8
votes
1answer
55 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
43 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
20 views

Model binding with a ViewModel

I have two ViewModels with the one referencing the other: ...
8
votes
3answers
86 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 ...
26
votes
3answers
944 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
161 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
37 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
347 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
199 views

Managing a cruise system

Follow up to Removing code smell from Room Booking code This program organises cruises in which it sets up the ship with cabins/rooms. It also does reservations with customer information and the ...
2
votes
2answers
159 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
25 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 ...
2
votes
3answers
105 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
184 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
238 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 ...
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
44 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
286 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
178 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
36 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 ...