C# is a multiparadigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform.
2
votes
0answers
14 views
Handling the loading of a video game's assets
I needed a small system to help in loading different types of assets for a video game, easily and efficiently.
To this issue adds the fact that sources are legacy formats (Amiga) and not ...
1
vote
0answers
29 views
How can I tackle this OOP design flaw in my Minesweeper Solver? [on hold]
Here is the BitBucket git source code: https://bitbucket.org/tgharib/programs/src/c18f655b44b0/C%23/MinesweeperSolver/?at=master
Here are the main classes that I am focusing on:
public static class ...
-1
votes
3answers
48 views
An exit condition for a do-while loop using lists [on hold]
I have an integer list l and a predefined integer value row (which is never manipulated inside the code). If value of row is 5, then I want the loop to exit if l contains 1,2,3,4. If it is 3, then l ...
1
vote
1answer
40 views
Unit of work and common implementation
I have some questions regarding a common implementation of the UoW, Repository Pattern and EF:
public interface IAppUow
{
void Commit();
IRepository<Customer> Customer{ get; } // ...
0
votes
0answers
25 views
Using reflection, how do you get class/struct constructor reference from a string? [on hold]
I was initially going to post this on SO, but after having typed it all out, I realized it was an awful question to ask there as I couldn't see anyone reading my question once the issue is resolved ...
3
votes
1answer
48 views
GameState Management efficiency
So I've read numerous tutorials on handling game states in XNA, and to each tutorial I've been read, it was different from the others. Now I want to ask which way is more efficient? I've created my ...
0
votes
0answers
20 views
NAudio ENet broadcasting program [on hold]
For about a month I have been trying to write a program that will allow me to broadcast a MP3 to a friend that would be listening to it on the fly. (like a radio). So I documented about what I should ...
5
votes
0answers
56 views
Simple Text Adventure: Cleaning up after the party
This week's Code Review Weekend Challenge is about implementing a simple console game.
Here's my game loop:
class Program
{
static void Main(string[] args)
{
var player = new ...
4
votes
2answers
26 views
Is Concurrent Collection Needed Here?
I'm playing around with switching some code to using Parallel.ForEach and I have a question about whether I need to be concerned about the effects of concurrency here. Here's a simplified version of ...
4
votes
1answer
40 views
Refactoring chart generator in Linq
I'm kinda curious how I'd refactor this in the best way. I've only used Linq for simple queries.
What it does:
Depending on the type that is submitted, we're grouping events or payments by ...
4
votes
3answers
63 views
Extracting pattern and simplifying testing
I observe the same pattern in a number of my classes but can't extract/abstract it due the tight coupling inside each particular implementation.
Having the class accepting an optional number of ...
0
votes
0answers
14 views
How to compare performance of Newtonsoft.Json library with JsonSerializer<T>? [on hold]
How to compare this Newtonsoft.Json library with this JsonSerializer<T> class on a given simple JSON?
class JsonSerializer<T>
{
static DataContractJsonSerializer xs = new ...
3
votes
0answers
43 views
Optimizing variable order Markov Chain Implementation
I've created a variable order Markov chain built on top of a tree, but I can't train on datasets >1MB worth of text without running out of memory. I'm sure the tree can be replaced by something else ...
0
votes
1answer
57 views
Is such style good for using unsafe features in C#? [on hold]
Is such style good for using unsafe features in C#? Or, why is it bad to develop such code?
#define LOLZ
using System;
using System.Threading;
using System.Runtime.InteropServices;
unsafe struct ...
4
votes
1answer
75 views
Implementing SOLID Principles with C# Asp.net
I have started learning about SOLID principles from yesterday. I've got a detailed explanation of SOLID principle here. After reading it and few other articles, I have tried to apply these principles ...
13
votes
2answers
171 views
Simple temperature converter
Below is my first attempt at programming a Celsius to Fahrenheit converter in C# winforms. I'm looking for tips and advice on improving my style and what I can do to make the code more ...
4
votes
4answers
204 views
Alternative to a large switch
Wanted to consolidate solutions to disparate problems into a single program.
I am worried that there is a interface, command pattern, or dictionary solution to what will become a massive switch ...
4
votes
3answers
66 views
Follow up to Pay Rate Calculator
Here is what I came up with. Hopefully if I have missed something that was said in answers on the previous question, we can still get those things pointed out. I am hoping that I made the code ...
2
votes
0answers
32 views
Feedback Requested : “Game” Engine Requirements System
I am/have been building a game for a long time now. The game is a web browser based system, and data is stored using JSON stored in RavenDB.
One thing I am very constantly running into as a problem ...
7
votes
5answers
179 views
Abstract Pet class
As a student of C# right now, I am trying my best to get a grasp on many of the systems being taught. I just completed Week 1 of a C# 102 class and the class was assigned a bit of homework. I am ...
8
votes
2answers
60 views
WinForms typing speed game
I've been writing a simple code just for fun:
This is a simple WinForms application with which you can measure your typing speed. There are three controls on it, doing the following:
rtbResults - ...
7
votes
3answers
98 views
Simple pay rate calculator
This little bit of code is just some code that I wrote from a flowchart at the beginning of a programming and logic book that I have added some to. I tried to create it as an object.
I would like a ...
4
votes
2answers
188 views
Simplifying `if` statements in Tic Tac Toe function
I'm currently trying to improve my coding skills, so I'm trying to code a Tic Tac Toe game. At one point a "win check" is needed.I'm using this code to check:
public void CheckWin(States state)
{
...
3
votes
3answers
93 views
How to make my code faster and easier?
This is my .cs part code where I am calling storeprocedure in LINQ to SQL:
var rr_j_cat = db.allcategories().ToList();//its store procedure calling thousands of rows
if (rr_j_cat.Count() != 0)
{
...
8
votes
1answer
155 views
Gotta catch 'em all!
This week's challenge is essentially about fetching Json data from the Web, and deserializing it into objects. I don't have much time to devote to this one, so what I have is very basic: it displays ...
3
votes
1answer
45 views
Retrieving statistics about URL clicks
I'm pretty new to ASP/MVC but have had some prior programming experience.
I am trying to retrieve statistics about URL clicks - total clicks and unique clicks by IP address. I started with:
...
2
votes
2answers
92 views
Should I create an empty string and append through a foreach loop or should I use StringBuilder? [closed]
Here's the current code:
static string GetResources(string header, string filter, string resourceTemplate)
{
string themeName;
if (!TryGetHeaderValue(header, "theme", out ...
4
votes
2answers
87 views
Are redundancy and reflection my only options here?
I have a function - TriggerNotifications - that accepts a NotificationType. The Type determines which settings I should pull from the User.
The code looks like this:
public void ...
3
votes
3answers
80 views
Inserting interval into a collection
The task is fairly simple. I want to create a collection of intervals and implement an Add method which would insert new intervals to the collection and merge overlapping ones. I would also like this ...
5
votes
3answers
138 views
Advice to improve code in simple webpage
I'm trying to make a few webpages that will allow us in the tech support team at the factory I work at to provide support faster by adding a simple interface to actions we perform everyday directly on ...
3
votes
5answers
116 views
Is there a better, more efficient way than Dictionary(Of Tuple(), MyClass)
Suppose I have data coming from different sources that tells me information about a large group of stores that has the following (just an example):
Necessary to define what store we're dealing with:
...
2
votes
3answers
254 views
Multiple lines of code in if statement without curly braces [closed]
I have used multiple lines of code in one if condition without using curly braces, which is executing properly. So what is the main necessity of using curly braces in if statements for multiple lines?
...
1
vote
1answer
46 views
EF adding Item with children
I'm working on my pet project with MVC 5 and EF, and everytime I'm adding a parent with it children (I have the children ID's) I have to go to the database, because if I just create a new child with ...
4
votes
7answers
246 views
One instance per method call or multiple method call per instance
I have the following class designs, and I'm looking for the best practices, aligned to the OOP design principles/patterns.
The ParameterParser will be used inside a foreach block through 10 items ...
1
vote
1answer
86 views
Is this good practice with unit-testing?
I've created unit test for the "student" CRUD operations that looks like this:
[Test]
public void Can_Exec_CrudOps()
{
#region Prepare
var account = Processor.Execute(new ...
9
votes
2answers
147 views
Multiple values against same condition
Is there any other way to optimize the below code? I feel the below code is huge for the operations it performs.
{
if ((currentElement == null ||
(firstGridRow["Low"].ToString() == ...
1
vote
1answer
47 views
Improving function when used from another class
The title could probably be better, but in any case here goes.
I am having a bit of a problem understanding how to move methods/functions to other classes to organize things.
So, I have moved a ...
4
votes
1answer
103 views
Generic Repository: Am I over-complicating?
I have created a generic repository for my MVC 3 page. I am using interfaces and a UnitOfWork. But before I set out to do this? Is this the right way to separate my databaseaccess from my viewmodels ...
5
votes
7answers
205 views
Which pattern to choose for passing alerts from service method back to user?
Considering the code sample below, which approach of service method design would be considered best-practice and why? The one used in SaveOrder1 or the one in SaveOrder2?
UPDATE: To be clear, I'm not ...
2
votes
1answer
43 views
VARIANT structure deserialization code organization
In my project i work with COM object via System.Reflection. COM object returns pointer on structure VARIANT, that i cast as object and then i cast one as byte array. There are many structures that i ...
3
votes
2answers
56 views
3 layer design and multiple dataset
I'm new to C# and OO programing.
I have an aspx page with 3 lists of checkboxes and I would like to generate them from the DB.
how should I structure my code?
Here is an example of what I did so far:
...
13
votes
4answers
210 views
SudokuSharp Solver with advanced features
Even though it's the first time I'm writing something this "big", it feels like I know C# quite good. It's been nice to learn LINQ also and I am very impressed by the features, and perhaps I have ...
3
votes
1answer
71 views
How can i reduce this code?
I have a problem. This code works great, but i think it can be reduced.
@if (Session["Success"] != null)
{
<text>
<div class="alert ...
2
votes
1answer
42 views
Best design pattern to approach http handler with multiple methods
I'm building an http handler at work which has about 6 methods and I'm trying to figure out what design pattern will work the best for my needs:
What's done already (Only an example to make this more ...
4
votes
1answer
86 views
Update only modified fields in Entity Framework
I'm working on a website on ASP.NET MVC4 and EF5. I want to ensure that only modified values are updated in the database. I'm using a unit of work pattern and repositories for data work. Here's the ...
2
votes
2answers
64 views
Sharing domain between ASP.NET and self running application
I'm building pretty big application and i wonder how should i share the code between asp.net mvc website and standalone (self running) server application.
I've got some idea how should i do this but ...
3
votes
1answer
85 views
Need advice on file/directory enumeration code
In various projects I need to enumerate all files and folders from a specific root folder, either on a local drive or across a network. I've broken the task down into two IEnumerable implementations ...
2
votes
0answers
57 views
Creating a masonry effect with varying height rectangles
The following is used to create a masonry effect with varying height rectangles. How can I simplify and make this more elegant in Unity?
private float startX = 0.0f;
private float startY = 0.0f;
...
5
votes
3answers
130 views
A c# class that represents an instance in Time
Please review my code and let me know of any additions or modifications that would make this even more useable.
The initial idea was to create a simple Time class that has only one function: To ...
6
votes
1answer
53 views
Sort ObservableCollection after added new item
For a WPF application, I have to sort the items in ObservableCollection after Added new item.
public void UpdateSource(ObservableCollection<SomeType> source, SomeType newItem)
{
...