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

Can this method be changed to remove all objects in one call?

I am converting a VB.NET app over to C#. I won't subject you to the old code but the following is done in a little over 100 lines using nested loops. I am using Entity Framework 6 as my ORM. I have ...
7
votes
1answer
59 views

Refactor VB.NET to C#.Net using Linq

I am rewriting a VB.NET application in C#. I will not subject you to the original code because it's pretty messy. Below is the converted C# code: ...
1
vote
1answer
16 views
2
votes
1answer
35 views

Transform DataReader to List<T> using reflections

I have implemented the code to convert datareader to list of objects. My intention was to not to use column name string literals while reading the datareader. ...
8
votes
4answers
1k views

Wow that's a big integer! What's its largest prime factor?

I see that there are a few other people who have tackled Project Euler Problem #3. I hope you're not all sick of that question yet. I've not taken a look at those yet (purposely), but am about to now. ...
1
vote
1answer
27 views

Access View from current/corresponding ViewModel

Sometimes when developing a WPF application, I need to access a certain Window (View) from the corresponding ...
0
votes
0answers
11 views

Memory Leak happening when using static instance of GsonBuilder to create Gson instances [migrated]

I am usong Google's excellent Gson library for doing JSON (de)serialization. I am making use of the GsonBuilder class to create ...
10
votes
3answers
447 views

Unit Testing for isPrime function

I've decided that I want to take a stab at test first programming. So, before I tackled writing an isPrime function, I wrote this unit test. It's my first and I'm ...
1
vote
2answers
45 views
0
votes
0answers
15 views

Basic Authentication with C#, XAML and MySQL [migrated]

I've been struggling for a couple of days to implement a basic login form in a C# project with no luck at all. The login form consists of two text boxes: the first is for the username and the second ...
0
votes
0answers
12 views

Generic Unit of Work & (Extensible) Repositories Framework [on hold]

Does anybody tried/implement work on this solution? https://genericunitofworkandrepositories.codeplex.com/ I'm looking at this code and seems like there is too much code and i'm not sure what is the ...
2
votes
1answer
44 views

Making Add and Edit DRY

I am coding a simple blog engine for educational purposes. In the PostsController I have two two methods that share some common code namely, ...
-1
votes
0answers
22 views

Representing a relationship between three entities [on hold]

I have the following relationship. Please suggest any better way of representing the following bidirectional reference: ...
3
votes
2answers
29 views

Simple IPv4 and port validation for chat client

This is part of my chat client's code. It works fine but it looks messy. Any ideas? ...
1
vote
1answer
30 views

HttpWeb* and XmlReader Async?

I've run into the need to deserialize XML that returns from an http request. I've done some light work with XML deserialization in the past but that was against files on disk. While attempting to ...
4
votes
4answers
262 views

A better way to do LINQ projections

I was wondering if there's a better way of doing LINQ projections than what I'm doing below. This method is one of many methods creating a view of an object tree. The first thing that I don't like is ...
1
vote
1answer
55 views

Duplicate code in similar classes where I cannot add more inheritance

I'm building a .NET Linq-esc query builder for my application and I'm wondering about my implementation and code structure when it comes a few classes. Basically I'm creating a query builder for SQL, ...
0
votes
2answers
85 views

Reusing too much code, but I cannot figure out how to refactor this correctly [on hold]

I have some code that run a series of functions in order and then outputs the results of each. When I execute this code, I am reusing a ton of it, where only the function itself in the code is ...
1
vote
1answer
34 views

Apply Good Patterns about Logging in Executor Process

I have source code for execute a command (ProcessStart) using Impersonate, and I want apply Best practices and good design pattern, and good performance if is possible. Too, I want use good Logging ...
10
votes
2answers
576 views

Too many objects, too “deep” class structure?

I have a pretty large model library I'm working on and it's turning out quite complex, or so I believe at least and I could use a second opinion. The basic idea is that the user should only have to ...
5
votes
2answers
54 views

Array 2D pairwise function

I found myself in the need of a function to pairwise an array 2D so I created one: ...
2
votes
0answers
20 views

Is this Repository/UOW design workable?

I'm using VS 2013/EF 6/WEB API 2. This application of mine which is working on will eventually grow to be big project and I'm in the very beginning stage and need your expertise to make it simple as ...
3
votes
1answer
36 views

Updating properties and states

I am rewriting a VB.NET application in C#. This code was originally done in 50 lines and I am trying to clean it up. As you can see I have gotten it down to 10 but I still feel its ugly. I want to ...
-2
votes
3answers
51 views

Arithmetic operation from string

I have a string like str = " 4+ 6 * 30";. I have to perform an arithmetic operation on this using C#; My solution to this problem is as follows. ...
1
vote
0answers
24 views

Sending a HttpRequest Message, and retrying in case of unauthorised

This code simply sends a HttpRequest message and, if it comes back Unauthorized, gets a new login and tries again. This code is meant to deal with the moment a ...
2
votes
0answers
32 views

Logging strategy setup

I finally set up my logging infrastructure to work as desired, however I feel like I had to do quite a lot things just to fulfill a few requirements. Now I'm worried if my approach has major ...
1
vote
1answer
43 views

Async function with slow web reference(web service) slowing down webpage

Is there a way to make a threading/async post with a web reference not slow down the whole website just because the web reference takes a long time to return a response? I have a send email function ...
3
votes
1answer
48 views

Changing these 2 Function into one function

I have two functions that are similar. The only differences is that their using two different models. How can i change them into one function? ...
3
votes
2answers
99 views

Determining if an entity exists in a database via a stored procedure

Here is a short and simple Ajax method that returns "True" or "False" if an entity exists in a database via a stored procedure ...
3
votes
1answer
27 views

Processes and Handling (Piping)

I basically have 3 processes which I loop through. The first process is encoding Video. It's actually 2 processes but they are connected, so I don't need to worry about how it handles the other one. ...
1
vote
0answers
28 views

Is the following code SOLID? [on hold]

I found the following code, which is used to write and parse CSV files, on the web. However, it seems it cannot handle the cases such as "|" delimited CSV file. Also does it violate any SOLID ...
9
votes
0answers
94 views

Trampoline Interceptor

Aim In C#, the following method will cause a StackOverFlowException if called with parameter 0: ...
3
votes
1answer
31 views

Return a List<MyObject> based on very similar data

I am rewriting an old VB.NET app in C#. I will not subject you to the old VB.NET code that I am writing (the original method that I have already refactored was over 700 lines long). The following is ...
3
votes
1answer
20 views

Data Access Layer method with transaction handling

I just want to know whether I've done transaction handling well. Also what about the other types of transactions available in .NET with regard to this code snippet? Also are there any redundant ...
1
vote
1answer
26 views

Service class for Archiving and Mirroring Files and Directories

I am writing an application that either mirrors a file/directory into another location or creates a zip file "snap shot" of a file or directory and stores it in another location. The user is able to ...
3
votes
3answers
101 views

WPF Calculator Code

I've coded a calculator in C# with WPF as the UI. I wish to know mainly about these points: Ways of optimizing Better techniques, tactics and ways of coding this All flaws on the surface as well as ...
3
votes
2answers
48 views

Multiple loops versus multiple stringbuilders

I've come across the following piece of code in a Razor view ...
9
votes
3answers
567 views

Finding largest prime factor from inputted number

This is my first C# console application. This program asks for an input of a number, and finds the highest prime factor of that number. Please review my code. Have I used things right? Is my code ...
0
votes
0answers
9 views

Organizing Business and Presentation entities [migrated]

Background I am developing a WPF project using the Microsoft Extensibility Framework. This is the basic structure: User Interface (WPF Project) MEF Interfaces (class library, contains all the ...
-1
votes
0answers
27 views

What is the advantage and disadvantage of WCF to WCF calling? [closed]

Is it fine to use wcf to wcf calling ? I have a WCF service which call a class library for Business Logic and These are in two different project in same solution.I have another project which is also ...
1
vote
1answer
62 views

Returning information about the result of a file processing, without using output parameters [closed]

As part of a C# class CsvConverter that converts various file types to CSV, I am designing a private class CsvConversionResult. ...
6
votes
3answers
189 views

Refactor a selection validator

I have a data table and have to validate every field in it. I have refactor this code to this below, but the complexity is 15(!!) Should I make something like dictionary with ...
2
votes
1answer
48 views

Reduce logic in Web API controller

I have the following scenario - i have a grid on web page that is populated with data. User can check a check-boxes in grid and data is saved to DB on navigating to next page. If they then navigate ...
5
votes
3answers
66 views

Read table row with multiple options

I developing an algorithm to read a row from a table (specifically, I'm reading from an Excel file). I have three conditions about when to terminate the Read operation: When an empty cell is found ...
3
votes
1answer
49 views

.NET WCF Activator for sync and async calls

I decided to re-write my code responsible for WCF calls, as all of my methods had try-catch-...
1
vote
0answers
16 views

Repository and Unit of Work asp.net/mvc/tutorials

I'm so confused after reading so many blogs I'm still not sure which way to go and I need help with Repository/UOF pattern using EF 6. As I was following the example here asp.net/mvc/tutorials and ...
3
votes
1answer
31 views

Find all collection properties of an object and get their values

I have a chunk of code that get's all of the ICollection properties of the passed in object and then takes all of their values and adds them to another ...
2
votes
1answer
52 views

Light Weight Actors

Edit: This was an absolute ignorance on my part which leads to hierarchical locks and can be implemented much cleaner (in fact the right way, in a mutable world) using a pipe-line of messages or ...
8
votes
1answer
197 views

Changing button colors based on user input

I am using C# to get the user's input of how many buttons to change the color of. The buttons are in rows that have 1-10 button in each. If the user enters 11, then the entire first row will be ...
12
votes
1answer
114 views

How can I better name my tests?

I am relatively new to TDD and am trying to adopt better names for my tests. I wrote the following tests abruptly and have since refactored them to the best of my ability, but despite my best ...