C# is a multiparadigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform.
2
votes
2answers
37 views
Get the next date based on a collection of valid weekdays
public static DateTime NextByDayOfWeek(this DateTime target, IEnumerable<DayOfWeek> validDaysOfWeek)
{
validDaysOfWeek = validDaysOfWeek
.OrderBy(item => item);
var ...
4
votes
4answers
110 views
How to optimize a multiple if-else with LINQ?
I have a static class:
public static class ConfigurationDetails
{
public static string SharepointServer { get; set; }
public static string Username { get; set; }
public static string ...
0
votes
2answers
38 views
Time of day based timer - run function at certain time, daily
I need to call a function exactly at certain hour, daily, my programs runs 24/7.
I wrote the following timer mechanism, which generally works that way:
Calculate time until hour and generate timer ...
3
votes
1answer
47 views
Marking class with no abstract methods as an abstract
Consider an interface:
public interface IWindowOperations
{
// Some operation methods.
}
Class definitions:
public abstract class BaseWindow<T> : IWindowOperations
{
// partially ...
1
vote
0answers
28 views
Elo system behaves oddly in program I've created [on hold]
Alright, so I'm looking to build a small program (C# and XAML) that, essentially, does this:
Generate array of players. Each player has a current rating and a true rating. I set current rating to ...
2
votes
3answers
131 views
When incrementing from 0 to 9, after 9 comes 0 again. Why is it a problem to use -1?
I have to create a button which counts from 0 to 9, and after 9 come 0 again. One of my friends said that this code is not good enough. Can you explain to me why is it a problem to use -1? Here's the ...
0
votes
1answer
41 views
Make WCF Service testable
I have WCF Service.
Its work fine and I want to have test coverage for it. Unit tests and acceptance.
The problem is static class using in the code.
How is it possible to avoid it?
If it will ...
3
votes
2answers
61 views
Custom database Lock - implemented with IDisposable
I have a lock class, that handels a database lock. It's not important how.
It is used in the beginning of a large operation, here is how it is used today:
public void LargeOperation()
{
try
{ ...
4
votes
3answers
139 views
Dice game rules implementation review
My in-laws taught me a dice game a couple years ago, and we play every once in a while. A recent excellent answer from @radarbob inspired me to proceed with translating the rules of that dice game ...
0
votes
0answers
29 views
Need help fixing errors in my C# homework program. How would I get this to work with the instructions [on hold]
I need help with a homework assignment that I am working on. First I will show my instructions, and then I will show the code I have so far.
My instructions -
create a C# program for Potsie's ...
2
votes
3answers
58 views
Generating and sending new password to user
Generate new password and send to user, if user is registered.
Two TextBox on page, txtUserName & txtEamil.
User can provide either UserName or Email to get new password.
If UserName is provided ...
2
votes
2answers
67 views
Is it needed to “beautify” this Stack implementation?
I'm just learning OOP, and I have an assignment to create a Stack. I came up with the following. Is it "beauty" enough, or to "schooly". Where can I evolve?
This is the class:
class Stack
{
...
2
votes
3answers
101 views
Shortening my questions code
Is there any other way to shorten this code without sacrificing readability? I am fairly new to C#, let alone programming, and I wanted to know if this is as short as this code can possibly become. ...
4
votes
1answer
75 views
Write a program to find the longest word made of other words
Lil' preparation before the interview. This is my solution to the problem in title. The code is pretty straight forward. The one problem is with substring it's O(n) in .Net and creates garbage. Any ...
1
vote
1answer
30 views
Simple WCF messaging system via EF
I'm open to any comments on this code/approach. Mostly architecture and threading. thx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ...
1
vote
1answer
21 views
Improving MVC 4 DropDownList
I'm currently populating my drop downlists like this...
public List<NewLogin> GetRolesForDDL()
{
using (database db = new database())
{
return (from r in ...
1
vote
1answer
54 views
Refactoring a collection of if statements that contain 2 arguments.
At the moment I have seven if statements that resemble the following code:
if(hit.collider.gameObject.tag == "Colour1" && start_time > look_at_time)
{
...
1
vote
1answer
56 views
Comparing data from two data tables
I have this code which compares data from two data tables. It does this by using a primary column and inserting the new record from table2 to table1. This loop continues for a large number of tables. ...
0
votes
1answer
78 views
Job Scheduler Implementation
I have created a Job Scheduler, and i want some review, new ideas for it.
Scheduler.cs
public abstract class Scheduler
{
#region Fields && Properties
private readonly ...
1
vote
2answers
56 views
Refactoring Into Generic Methods
This might be a loaded question, but here goes. I have some code that is very similar between all the methods. I am trying to find a way to accomplish all methods with a generic method/function. I'm ...
3
votes
2answers
72 views
Function that builds dictionary based on lambda params
I've written a method in c# that allows me to do create a dictionary from a passed in object and N lambda expressions that reference that objects properties and methods. It's working the way I want it ...
2
votes
1answer
105 views
Producer/Consumer in C#
Is the following implementation correct?
private int _count = 1000;
private Queue<string> _myQueue = new Queue<string>();
private static object _door = new object();
public void ...
0
votes
1answer
40 views
Counting sort review
I've just wrote a program in C# for counting sort.
space complexity is O(N+K)
time complexity is O(N+K)
I want reviews on my code and any better ways to implement this.
namespace SortingSelfCoded
...
2
votes
1answer
130 views
DAL Efficiency Help
I am attempting my first try at some c#. So far I love it, (not more than vb tho ;)) however, I am wondering if I can make these classes a bit more efficient.
Please note ###Test is my attempts at ...
2
votes
1answer
31 views
Receiving MSMQ messages as a list
I am unsure if the list could store a large number of messages.
There are 50,000 queue messages which I am receiving and assigning to the messages list:
var msgEnumerator = ...
2
votes
1answer
36 views
Exporting PDF From Database back to PDF Format
Answer to Exporting PDF's from SQL Server DB and writing a Map to a Text File
this was a Question that I asked in StackOverflow and then answered it when I was finished with the project.
I would ...
1
vote
1answer
35 views
Initialization of Extended class without too much overhead?
I am getting object of a class AAA from somewhere and I want to add more information in that object. So, I am creating a new class BBB which is derived from AAA. The class BBB has additional field ...
4
votes
3answers
200 views
Win Forms design pattern
I am writing a dice roller win forms application using C# 2012 VS. Dice roller is set up for playing Shadowrun table top. I feel that there might be too much code going into the GUI, but I am unsure ...
1
vote
2answers
39 views
IsoSettingsManager
Just a wrapper around IsolatedStorageSettings.
The only thing i'm not sure about is isoSettings.Save(); Should i call it there? Looking like it works without it, setting [] is enough.
class ...
0
votes
1answer
36 views
Random string generator [closed]
I have made a simple number generator, and I have a question: is it possible for the generator to eject "red", "blue", "green", " yellow" and "white" instead of the numbers 1-5?
namespace ...
2
votes
2answers
53 views
Optimizing odds calculator
I am trying to setup an odds calculator for a best of 7 series, given independent odds for each event.
The following code works, but I would like to add recursion to simplify the end.
public class ...
4
votes
2answers
71 views
Optimization of comparing two collections and get the changes
I use the following code to get the changes between two collections. Objects are "joined" using a primary key. Any tips on performance issues or other optimizations appreciated.
/// <summary>
...
2
votes
1answer
42 views
Simplest WP7 logger
Just ended up with this approach for wp7 (no tag yet), in case someone would find it useful. Also, improvement considerations are welcome.
It works with
SimpleLogger.WriteLine("JustLine");
...
1
vote
2answers
70 views
Covariance in generic collections
I have a some classes and interface
public interface IGeoObject
{
GeoCoordinate GetGeocoordinate();
}
public class User : IGeoObject
{
public GeoCoordinate ...
2
votes
3answers
52 views
Function for encoding strings in-place
I recently wrote a function that replaces every white space with '%20', just for fun (and sharping my coding skills). The input string is terminated with extra white spaces, with the length that the ...
1
vote
0answers
30 views
Quora Nearby challenge [closed]
I am trying to solve the first problem (Nearby) in Quora's programming challenges. I've tried a naïve approach with C#. I was able to get correct answers for the first 2 inputs, but am facing a Wrong ...
3
votes
1answer
59 views
Need reviews for an authentication system
AccountController Code:
public class AccountController : ApplicationController
{
public AccountController(ITokenHandler tokenStore, IUser user) : base(tokenStore, user){}
public ...
2
votes
1answer
81 views
array with reusable elements
I need array to store elements, but I don't want to make memory allocations at runtime. So I reuse elements. Some fields are never changes so as I reuse elements I need to assign those fields just ...
4
votes
2answers
101 views
Need a review for a function that returns the 3 latest dates
Just putting together a small project, checking to see if this would be the fastest/cleanest way to write out a function that grabs the 3 latest vital signs.
Edit: I am thinking GetRecentVitalSigns ...
1
vote
0answers
75 views
Using LINQ ForEach instead of for/foreach (from a code quality PoV, not performance) [closed]
I was peer-reviewing some code recently and there was a particular thing that bothered me (although I could not tell why), regarding the use of LINQ expressions.
Every single loop was written as a ...
4
votes
2answers
79 views
Alternative to starting enum values with a number?
I have an enum like the following:
enum MeasurementBandwidth
{
Hz1 = 1,
Hz3 = 3,
Hz10 = 10,
...
}
But I do not like the Hz1, but 1Hz is not valid as it starts with a number.
Does ...
1
vote
0answers
44 views
Improve the architecture to cache data
I cache the data and use local database in my Windows Phone app. Algorithm is very simple:
Get data from DB and show in UI
Get data from a web service and show in UI
Update data in DB from the web ...
1
vote
2answers
69 views
Implementing Peek to IEnumerator and IEnumerator<T>
Many of you might have come to the point and wished to have a Peek for IEnumerator and IEnumerator. I tried to implement it by cheating a bit and looking up the next element before the actual MoveNext ...
3
votes
2answers
116 views
Secure Password Hashing in .Net - Code Review
I have found a password hashing article and an implementation.
Is this code secure if I increase the salt to 64 bytes, hash key size to 128 bytes and the iterations to 10000? Are there ...
1
vote
1answer
47 views
How to deal with interface inheritance and common properties? [closed]
I'm trying to design a generic caching system that takes keyed items and allows either read-only or read-write access to a cached version of it. The read-only backing interface is:
public interface ...
3
votes
4answers
163 views
What is the potential risk with this code?
I am trying to implement a distinct counter to detect if all tasks that is added to the ThreadPool has completed and want to use it as a barrier. So, when a function that is added to the ThreadPool is ...
4
votes
5answers
79 views
Reference type and constructors
Code in Java but should be readable also for c#...
Let's assume I have a class with some reference types. Example:
class MyClass {
private int uniqueId;
private double doubleValue;
private ...
1
vote
0answers
18 views
Metadata query performance optimization
SQL Server 2008 R2 + .NET 4.5:
I have the following metadata table:
CREATE TABLE [dbo].[Metadata](
[Id] [uniqueidentifier] NOT NULL,
[ContentId] [uniqueidentifier] NOT NULL,
...
2
votes
3answers
75 views
Dealing with non-required user input
I'm working on a page where a user can create new records, but not all values are required. When creating the SqlCommand with potentially null values, I'm wondering what's the best way, from a code ...
1
vote
1answer
127 views
Implementation of a coin jar
Implement a coin jar in C#. The coin jar will only accept US coinage
and has a volume of 32 fluid ounces. Additionally, the jar has a
counter to keep track of the total amount of money ...