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

DiagnosticAnalyzer for Roslyn that guards against catch-all exception clauses

Dabbling around with Roslyn and made a small analyzer just now. This one will show a warning in Visual Studio when you have a try-catch statement that only has a ...
6
votes
2answers
138 views

Looping through an Excel document in C#

Before looping through an Excel document using a library I found, and wanted to know how long it would take to loop through the whole thing. There are 40k rows. I looped through only the first 5k ...
2
votes
2answers
38 views

Recursive function for listing directories [on hold]

The below code is recursive function that list directories in 2 levels: ...
2
votes
0answers
50 views

OOP between projects

So, I wanted a separate project to act as the data layer for my website project. Classes in the website should reference the data layer after getting input from the user and should get back ...
7
votes
2answers
247 views

Generate sequence in linq

I want to generate a sequence using linq that goes form 10 to 100 with a step size of 10. The sequence also must contain a custom value (in the correct order). This is what I have now, and Im ...
3
votes
2answers
34 views

C# with Oracle ODP.NET

...
0
votes
0answers
32 views

Group By And Two Counts

I'd like to know if there's any better way to write this query: ...
-1
votes
0answers
23 views

Program Settings using Adapter pattern [on hold]

I'm working on a program at work that is both a keyboard wedge and keyboard hook. I may have made a mistake on the two wedge configurations, but I have 1 wedge as a base which just takes a com port, ...
3
votes
1answer
50 views

How to provide best integrity for interfaces in C#?

I am trying to apply Interface principles into my code, learn by practice method. I have a CRM system that has Notes, Payments, DairyEvents and anything else that needs to be bolt on over time. I ...
4
votes
2answers
73 views

Retrieve Tasks by Employee

I think I've done a decent job keeping this query simple and understandable, but I'd like to know if you have some more advice. My relevant entities are defined like this: ...
3
votes
1answer
75 views

Falling Rocks Game

I have implemented the Falling rocks game in C#. The instructions are simple: Don't get hit by rocks. The game is running quite well, however there are some bugs that occur and furthermore, I would ...
6
votes
1answer
53 views

Reading data from excel sheet with ExcelDataReader

Objective: I want to import an excel file, and read the rows of certain columns. For this, I use ExcelDataReader. I implemented a low-level class called ExcelData which uses the ExcelDataReader and ...
1
vote
2answers
76 views

Converting Anonymous To Dynamic [on hold]

I have a extension method like following that takes Anonymous type objects and returns it after converting into ExpandoObject which falls under ...
5
votes
1answer
89 views

MVC 5 & EF 6 - Repository & Unit of Work Pattern

I have been looking through Code Review on the subject of Unit of Work and Repository patterns and realised that my implementation appears to provide very similar functionality but in reverse class ...
9
votes
1answer
131 views

QuickSort C# Implementation

It has been a while I haven't implemented a QuickSort and I wanted to write it down like I remembered. Here it is: ...
4
votes
1answer
40 views

Using static management class to control db transactions through an EF6

I have the class below to manage my specific implementation of a membership system using entity framework 6.1 Is the use of static access correct in this case? as far as I understood that EF context ...
3
votes
1answer
61 views

Using model view presenter (MVP) in C# code

I'm a beginner to Model-View-Presenter pattern and I'm finding a way to use it in a sample application In my C# winforms application has a Employee Class and it ...
7
votes
4answers
82 views

Check if XmlNode with certain attribute exists and create XmlNode if not

I'm not going to explain the purpose of the code provided below. If you do not understand it, i know that i have to improve it (naming, structure etc.). I would like to know how to improve this code ...
11
votes
2answers
222 views

Displaying data from a database onto a form

I'm a beginner to .NET and could you guide me to right direction. My problem is based on the following code. Here I have 4 variations of same method and all 4 variations are working fine. What is ...
4
votes
2answers
58 views

Entity Framework Skip and Take too slow

The following code achieves what I require, reading 10000 rows at a time: var query = repository.Subscribers.ToList().Skip(numberToSkip).Take(numberInBatch); Is ...
6
votes
2answers
154 views
4
votes
1answer
50 views

Amalgamation of the repository and command / query pattern

I am coding a web based solution which consists of N number of tiers, these are: UI Web API Business The question I have is related to validation, repository and CRUD operations. I am adopting the ...
8
votes
2answers
130 views

Refactoring class methods to helper class?

I have an abstract class that represents data request. The request is in XML format. There are a few classes that derive from abstract class and they do similar things. Some basic XML operations such ...
4
votes
1answer
60 views

Is this Shell sort?

Trying to learn shell sort, I kinda understood what wikipedia was trying to say, but I wanted a bit of confirmation, so I went on youtube, here, but this code does not work and does not look like what ...
9
votes
4answers
824 views

Constructor to transform an Outlook contact into a Dynamics CRM contact

This is my constructor to transform an Outlook contact into a Dynamics CRM contact: ...
7
votes
2answers
337 views

Returning the result of whichever method finishes first

Consider a method (let's call it IsPrimeHybrid) which calls at least two methods (let's call them IsPrimeNaive and ...
2
votes
2answers
33 views

WinForm plugin architecture

I have been developing this plugin architecture, mostly for fun and education, its a simple WinForm with some plugin logic and two plugins, i want to know if there is a better way of doing it. ...
-2
votes
0answers
28 views

using task parallel library and linq - unable to detect Null reference exception [closed]

One of our Console application was working fine but started failing in Production with null reference exception. We can't debug as of now because we don't have access to Production and getting ...
-1
votes
0answers
24 views

Default Keyword cause namespace issue [closed]

I'm trying to do a simple null check on an unknown type so I'm dynamically changing its type in the following function. Everything is cast as objects right now to simplify testing. However the ...
0
votes
0answers
23 views

Converting JSON properties to numbers when serializing using Json.net and C# [closed]

I want to output the following example data in JSON: {"source_id":"1234","contacts":["15":"020 8111 1111"]} I've tried using the following code to achieve this using Json.net: ...
4
votes
2answers
96 views

Can calculation of word wrapping be made notably faster?

I need to re-wrap a text so that it fits a given width, font and DC. The result needs to be an array of lines. I use the following code: ...
3
votes
1answer
74 views

Unnecessary unit test?

I have this method in my service layer ...
3
votes
3answers
125 views

Is it possible to do constructor chaining?

As I understand the constructor chaining can be applied to cases when we have some common data to initialize. I have 3 constructors that accept 3 different types of arguments and have some common ...
2
votes
0answers
32 views

Abstracting Windows Azure table storage

I wanted to test some in-memory service classes that ultimately inserted data into Windows Azure Storage tables, so I have attempted to abstract the storage so I could swap it out with an simple ...
3
votes
1answer
74 views

Winning Pattern Detection [on hold]

This was a question asked to me before setting up an interview. You are given a game board that contains a four by four (4x4) array of pieces. The pieces can be one of six shapes and can be one of six ...
6
votes
3answers
105 views

Unit tests: to cast or not to cast?

Suppose the following example unit test for an ASP.NET MVC controller: ...
0
votes
0answers
29 views

WSDL Creator check in C# [closed]

Some time ago I was write PHP wsdl-creator. After this I got a reply in this issue: #6. Problem was in binding types, and I add document/literal support. Can someone with C# check is generated WSDL ...
7
votes
4answers
398 views

E-Commerce 'sale price' calculator

I have code which I need to refactor in order to use in many places. So I tried some solutions but always ending with repeated and messy code. So, I decided to ask what possible best solutions are. ...
2
votes
0answers
54 views

Implementing the Repository Pattern

I'm new to this pattern and I see arguments online about different implementations. I have the following code and it seems fine to me, but I'm wondering if having to pass the DBContext into the ...
6
votes
3answers
103 views

IDisposable Interface for an Server/Client connection client

Here is a class of one of my applications I'm trying to learn writing good code with. Old Code: ...
-1
votes
0answers
35 views

Constructor Conventions [closed]

I have a class that I am attempting to write the constructors for and I am having difficulty deciding the correct way to do them. I was first thinking something like this: ...
1
vote
0answers
50 views

Getter Setter conventions [closed]

In C# I am creating properties in different ways. Like this: public Dimension X { get; set; } and like this: ...
1
vote
3answers
804 views

How to remove file extension using C#?

I am trying to remove file extension of a file with many dots in it: ...
3
votes
1answer
39 views

Linq sorting on sort order of inner group

Is this the best way to do this sort? ...
7
votes
3answers
460 views

How to refactor multiple if statements?

The code I want to refactor look as following: ...
4
votes
0answers
49 views

Manually Populate DataGridView With Accounts/Credentials

I'm designing a small account/password manager using C# and SQL Server CE. LINQ to SQL is my ORM of choice. Here's the data model representing how the SQL Server CE database is set up: And here's ...
3
votes
3answers
61 views

Census Data Display from Text File

This program is for a class project and requires me to read data from a text file then display a list of totals. Here are the instructions/requirements: The fields in each record will be separated ...
6
votes
3answers
335 views

Bit exchange operation

I have been working on a certain task these days and after several hours of torture, I have done it! However, I believe the code that I have "crafted" is quite difficult to be understood and to be ...
5
votes
1answer
71 views

Is there a simpler way to create this Inheritance structure for overriding an internal Generic Type?

I have some code below which is designed for the following purposes: Implement a cache structure which stores cached elements, as well as a method for reloading those elements. Ensure the new ...
5
votes
1answer
41 views

CountdownLatch: Is this thread-safe?

I am trying to learn how to write correct lock-free code. I've written this class out of exercise for a synchronization construct to be used across multiple threads. The intent is to have worker ...