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

1
vote
0answers
4 views

Chained extension methods on collections

There is an API that returns me domain objects over which I have no control. These domain objects have a hierarchy and I need to enumerate all objects from of specific type from the whole hierarchy. I ...
3
votes
4answers
183 views

Shortening boolean with if statement for document version comparison

Can this be shortened to one line? ...
-3
votes
1answer
37 views

Declaring the reference of an object within a for loop [on hold]

Please let me know which approach is better case 1 or case 2 and how? Can anybody please explain how it is different if we create the refernce of the object inside the for loop. Case 1: ...
0
votes
1answer
32 views

Optionally specifying the type when implementing a method for an interface [on hold]

These seem functionally identical: public class Temperature : IComparable<Temperature> { public int CompareTo(Temperature other) { } } as opposed ...
0
votes
1answer
25 views

Get the condition that does fails in a complex boolean expression [on hold]

I have a complex boolean expression with many conditions. I want, if it is possible, to refactor it so I can get the first boolean condition that is false (will stop parsing boolean conditions as ...
5
votes
1answer
42 views

Stable Sort in C#

I wrote a stable sort algorithm in C#. It is just a simple iteration, and is probably not very optimal: ...
5
votes
2answers
80 views

Wiring CollectionView and updating itself without the need for Refresh()

I have been using your expertise developing my application using parts of WPF that I have never touched before. In this stage my View does all I need him to do, however, I am not sure if I've done ...
14
votes
5answers
670 views

Passing parameters by reference? Let me fix that for you

I've implemented a code inspection that verifies whether a procedure has parameters that are implicitly passed by reference - in VBA a parameter is passed ByRef ...
6
votes
7answers
269 views

Create a new Member

I was tasked with member creation on a site that was already developed for Active Directory, so the log in functionality was there and most of the site was all ready to go (after minor major tweaks). ...
9
votes
4answers
579 views

Refactor foreach loops

I have 2 objects and I am comparing them to see which fields are equal and which are different. But I am not sure my loop is 100% correct. Does this look ok? If so, what other ways could this be ...
-5
votes
1answer
69 views

Sum up all my web requests and make them static [on hold]

Context: I'm currently developing an iOS app in C#. I have different view controllers and sometimes also another view controller needs to make the same web request. I don't want to hold a reference ...
4
votes
2answers
753 views

Running Code Just Once

I want a code run just once (say in Dispose). WriteOnceBlock<T> from TPL Data Flow could be used here; but again if we ...
9
votes
3answers
513 views

Winforms Circular Checkbox

So here is my next creation, a circular checkbox. This is my third custom control, so I'm still learning, but have the basics just about down. Tips and suggestions are most appreciated: ...
3
votes
1answer
50 views

View model usage

I'm about to start work on a large project using MVVM design pattern. I've worked on smaller projects in the past using MVVM, but I want to make sure my approach to MVVM is good/manageable as possible ...
4
votes
2answers
57 views

Shoot the Messenger Part 3

This is a follow up to: Messenger supporting notifications and requests Shoot the Messenger pt. 2 I've written a lightweight (I think) class that acts as a messenger service between classes for ...
5
votes
1answer
53 views

Create a tree recursivly

I want to create a Treeview in C# which will group file by prefix (here the prefix is a marked by the separator _). The following files should give this tree: ...
8
votes
1answer
69 views

WCF Duplex service authentication

I have been thinking about a way to implement this and I am not sure that what I have done is correct, because it surely sounds kinda dirty to me. Basically what I have is a WCF duplex service which ...
11
votes
2answers
511 views

Counting Calories

I have this program for counting calories. There isn't a whole lot to it yet. It's a moderately sized project, so I'll do my best to make it as short as possible, posting only the main of the program ...
3
votes
4answers
150 views

Using readonly field instead of private setters in struct

This is supposed to be an immutable structure representing a time-stamped value. Since it represents a physical measurement, it cannot change, and I want to make sure it really doesn't change ...
5
votes
2answers
350 views

Abstracting a Password Service

I want to use Microsoft.AspNet.Identity's PasswordHasher but I don't want to pollute my Domain layer with knowledge of it. As ...
12
votes
2answers
125 views

I think I might be having a regex nightmare

I've been working on the Rubberduck (an add-in for the VBA Editor /"VBE"), specifically here the VBA.Parser namespace. Here's how I ended up implementing the syntax ...
2
votes
1answer
34 views

3Sum 2 Different implementations complexity

These are 2 implementations for the http://en.wikipedia.org/wiki/3SUM problem, The first one is mine. and in the second one I implemented Wiki's pseudo code. Can someone please tell me if there is a ...
8
votes
3answers
87 views

Implementing StrStr()

This is a naive implementation - I know that there are algorithms like KMP However I was trying to implement it as best as I can. ...
2
votes
4answers
121 views

Implementing Substring in C#

I was trying just as a practice to implement substring on my own. the Test is inside the Ctor just because it is easy. ...
16
votes
2answers
492 views

Enum, constants, or other to represent chess pieces

I'm learning C# and I decided to write a chess program to help me practice the concepts I'm learning in my book. I started the Board class tonight, which is going to handle 1) the board state and 2) ...
3
votes
1answer
43 views

Basic TCP server client application

I've written a basic server/client application to use in an automation application written in C#. The code is working pretty good, but I have a few thing I want to improve: Server: ...
8
votes
0answers
53 views

Observable timer sequence

This question over on SO about how to call a function "later" using Rx led me to post the following ill-advised piece of code to solve the problem: ...
7
votes
2answers
164 views

Refactoring a FTPHelper Class

I've written a FTPHelper class to help teach me more about code strucutre. I don't know what I don't know so I would really value feedback on how I can be laying out and thinking about my programming ...
6
votes
2answers
91 views

Tree traversal into List

The interview question was to traverse a tree into a list. ...
5
votes
1answer
49 views

Word break problem with dynamic programming

This is the original question. I have implemented it in both ways. If I enter the word "icecream", should I output "ice" "cream" and also "icecream", or just "ice" and "cream"? Is this a good ...
4
votes
2answers
59 views

Pairing anagrams in a string list

The task was to check for pairs of anagrams in a string list. I first sorted all the words. and looped over the letters. The interview continues with a follow-up, to do the same with limited memory. ...
5
votes
1answer
35 views

Monotone cubic interpolation

http://en.wikipedia.org/wiki/Monotone_cubic_interpolation We have implemented it using the formula from Wikipedia : ...
4
votes
3answers
107 views

String reverse and pairing reversed words

These are questions from an interview: Reverse a string Find matching anagrams in a word list ...
5
votes
3answers
67 views

Code redundancy issue while feeding dropdownlists

I have a dashboard to manage a learning center system. There are scenarios like admin create learning center and define a classroom in it and then assign some courses in it and assign students to ...
3
votes
1answer
31 views

Invoking only the last registered event handler

We are building a game and we have a dialog system. Dialogs may open and stack on top of one another. When every dialog opens, it registers itself to handle the BackButtonPressed event: ...
4
votes
2answers
40 views

Is it ok to add a static method to the IEqualityComparer implementation?

Linq methods like Distinct need IEqualityComparer object. But sometimes I just compares two objects and to create Comparer instance for that is seems redundant. So it would be nice to use static ...
6
votes
3answers
311 views

Best way of updating a list of unique items

I am wondering what the best practice for updating a list that only accepts unique items. Right now, I have a button that loads data from a database into a list. I can press this button numerous times ...
13
votes
9answers
602 views

How can I refactor to avoid repetition finding the index of strings in a list?

I have a list of strings where I want to find the index of a first- and second-choice video compressor. Logic: If the first choice is available, return its index. If not, and the second choice is ...
6
votes
2answers
81 views

Enemy patrol script using NavMeshAgent

I'm piecing together an Enemy script to attach to my characters. This is the portion that related the a game objects ability to patrol to given locations. ...
7
votes
2answers
73 views

Correct usage of MVVM and object for method

I'm writing my first C# Windows Store app and am learning C# from scratch. I'm trying to implement MVVM as I understand it and object orientated patterns, obviously though I'm expecting to be doing it ...
2
votes
2answers
66 views

Streamreader file.Readline properly closing the stream

Is this OK? (.Net 4.5) ...
1
vote
1answer
56 views

Simplification LINQ query and other code

I need to simplify the below code as well LINQ query: ...
7
votes
1answer
381 views

Math expression parser in C#

EDIT: Added refactored version 2.0 to the end! I have a parser that is supposed to take a string similar to a math expression and return a Tuple of: An array of strings where each string ...
5
votes
1answer
157 views

Drying Up Very Similar Implementations of an Interface

Work continues on the Rubberduck VBA Editor Add-in. I have a need to call some VBA code from the add-in with Application.Run. Unfortunately, the ...
7
votes
1answer
95 views

Displaying a video player to eligible users

I posted this on Stack Overflow, but it was suggested that I move it over to Code Review. I would like some feedback on the way I decided to clean up code from the in a .NET project that had ...
7
votes
3answers
80 views

Removing equivalent authors in a list

I have a list of authors, where seeking duplicity. The indexes of these duplicates are stored in a list of lists named duplicity. For example, at index 0 in the list duplicity is nested list, which ...
5
votes
5answers
163 views

File System Read Buffer Efficiency

Context I'm working on a new Enterprise Library at my company and I am implementing some code that will be used to read files into memory. Since this is an enterprise library to be shared across the ...
8
votes
2answers
92 views

Printing all even and odd numbers with threads

The original question is on careercup. Write a multi threaded C code with one thread printing all even numbers and the other all odd numbers. The output should always be in sequence ie. ...
14
votes
5answers
2k views

Tic Tac Toe in the Console

I have made a Tic Tac Toe game in C#. How can I improve my code? The full listing is as follows: ...
1
vote
1answer
65 views

Account view with MVC and paging

My Model ...