C# is a multiparadigm, managed, garbage-collected object-oriented programming language created by Microsoft in parallel with the .NET platform

learn more… | top users | synonyms

4
votes
3answers
286 views

How to avoid the LoadBy pattern?

In our codebase for a sophisticated system controlling many aspects of businesses, we have a certain unwritten law to not fudge around in code with complicated SQL, instead writing it into a function ...
25
votes
5answers
2k views

Could an instance be equal to some other instance of a more specific type?

I've read this article: How to Write an Equality Method in Java. Basically, it provides a solution for an equals() method that supports inheritance: Point2D twoD = new Point2D(10, 20); Point3D ...
0
votes
1answer
184 views

How to structure a chain of method calls [duplicate]

To keep it simpler for any client of my class, I have put a sequence of private method calls within one public method. The client then calls this method and all the methods within run to complete the ...
0
votes
2answers
335 views

Am I overusing Inheritance or this is exactly what it is here for?

I have a class called BagItem and another class called EquipmentItem both classes are exact the same in methods, etc, with the exception of 1 property. BagItem have: public InventoryBagType BagType ...
3
votes
2answers
141 views

C# Abstract math classes from libraries

I'm currently writing a library that abstracts 3D rendering and uses SharpDX and OpenTK as graphics libraries. The problem is that OpenTK and SharpDX have their own implementations of Vector2, Matrix, ...
4
votes
2answers
148 views

Exposing nodes in a generic binary search tree implementation to visitor pattern

It's common to implement binary search trees with an internal Node class public class BinarySearchTree<TKey, TVal> { class Node { public readonly TKey Key; public ...
0
votes
0answers
88 views

C# Event listening methods

I recently downloaded VS 2015 and when writing an event handler, it auto completes a generic method for you, but it does so differently that what I learned/used. This is how I would normally write an ...
-4
votes
1answer
141 views

Class library naming conventions [closed]

Typically in a C# program, the entry point is in Program.cs. However, if you are creating a rather generic class library, with no Main() method, such as TCPClient.dll what is the appropriate base ...
0
votes
2answers
121 views

If it's a static object is using ref as method argument better?

I have an object 'connection' which holds the path/credentials to a SQL DB. When calling methods; we usually do this: Connection con = new Connection(); GetSalesData(con); public static void ...
-4
votes
4answers
288 views

Why aren't named switch statements a language feature? [closed]

I could imagine the below code being somewhat useful. Is there a reason this pattern hasn't made it into programming languages? To be clear the string was just what I chose as an example you could ...
0
votes
0answers
101 views

Enclosing curly braces around objects, reasoning behind it? [duplicate]

I've seen some snippets of code do the following: CalculateSum mySum = new CalculateSum(); { mySum.add(50); }; while other developers do it this way (without the enclosing braces: CalculateSum ...
1
vote
0answers
122 views

MVVM viewmodel to view correlation in adaptive UI

I am making an mvvm application for the uwp platform and I am looking for advice on the following matter. Take for example the windows 10 e-mail application, which when full screen displays both the ...
-2
votes
1answer
196 views

Searching for 2 numbers that equal 10 [closed]

During an interview today I was asked to write a function that accepted an array of integers and return the positions of two values in the array that the sum was 10. My code was C# public string ...
14
votes
3answers
548 views

How can I diagnose async/await deadlocks?

I am working with a new codebase that makes heavy use of async/await. Most of the people on my team are also fairly new to async/await. We generally tend to hold to Best Practices as Specified by ...
0
votes
1answer
143 views

C# Application GUI design dependent on configuration

I have built quite big WinForms application working in industry for a few years. It communicates with many HW devices. Application can be configured to use or not use some of these devices and GUI is ...
3
votes
1answer
147 views

Does Having DI Happen in the Composition Root go against the whole point of Dependency Injection?

I am using Dependency Injection for a .NET MVC web application in which I have three basic layers: 1) Web App 2) Service Layer 3) Data Layer I inject the data layer into the service layer and the ...
0
votes
2answers
106 views

Change number of publishers/subscribers at runtime

I need to redesign distributed Publish-Subscribe solution in our product. Problem description We have several producers (NT service), queues (MSMQ) and consumers (IIS server). Task handling requires ...
8
votes
4answers
1k views

Will the Database connection be closed if we yield the datareader row and not read all the records?

While understanding how yield keyword works, I came across link1 and link2 on StackOverflow which advocates the use of yield return while iterating over the DataReader and it suits my need as well. ...
1
vote
1answer
160 views

Is there an reason to call the base constructor of object?

I wonder if there is any reason to call the base constructor when inheriting from object. class Foo { public Foo() : base() // calling the Object constructor { // Foo ...
-2
votes
0answers
260 views

Reasons to want false-negatives when comparing strings (or string references)? [duplicate]

Java programmers know that new String("some-text") == new String("some-text") evaluates to false because two different objects/references are being compared [and that String.equals should be used to ...
1
vote
2answers
143 views

WCF service design

I am rather new to WCF (or rest, or Json for that matter) and I'd like to have some expert opinions on which methods to define. Some short introduction to give an idea of what the webservice should ...
3
votes
5answers
975 views

When are enums NOT a code smell?

Dilemma I've been reading a lot of best practice books about object oriented practices, and almost every book I've read had a part where they say that enums are a code smell. I think they've missed ...
2
votes
1answer
178 views

What is the best way to horizontally scale .Net back-end applications?

Given a workload with many long running CPU/IO intensive operations (e.g. producing multi-GB text files from database reads and business rules), what is the best way to balance .net application load ...
2
votes
3answers
422 views

Multi user website for MVC project: one, or multiple solutions?

We're starting a new MVC 5 project that will ultimately consist of 4 websites depending on the kind of user: One internal, for company employees. One for agents, independent contractors that work ...
2
votes
1answer
172 views

Writing a programming api for an existing project? [closed]

I've an already existing project in C#. Now I should implement a plugin system. For this plugin system I've to implement a programming api/sdk. I dont want, that plugins have access to the assemblies ...
1
vote
0answers
138 views

ASP.NET, OWIN, and self hosted web interfaces [closed]

I would like to develop a web browser based interface that can be accessed locally and remotely for a C# console application. I would love this to be a light weight, self hosted app if possible (as ...
1
vote
2answers
488 views

C# .NET MVVM software architecture and naming conventions

I am currently working on a software using C# .NET and WPF with the MVVM pattern. Though the software is almost done, I have been discussing our architecture for a long time and I would like to get ...
4
votes
2answers
181 views

In Web API is it a good practice to wrap the results with my model? [closed]

I have a Web API, and I'm thinking if it's a good idea to always wrap the result with a my own result model which will always contain specific structure like: { Data:(of type T generic), ...
0
votes
1answer
97 views

storing single character value use string or int C# [closed]

While storing single character value for the purpose of status, gender, delete_flag etc. which is better data type string or int. Suppose :: status = A/I or status = 1/0 gender = M/F or gender = 1/0 ...
1
vote
1answer
149 views

Modular Filter Architecture for WPF

I am creating a little stock-management tool for private use. I have different views, which need similar but different filters. As an example i have a "current stock" list where i can filter for ...
3
votes
2answers
239 views

When to use Constructor and when to use Collection Initializer?

I am having a .Net class which has 10 properties like given below: [the datatypes of individual property is just a placeholder here and it can be anything from a primitive type to an object to a list ...
0
votes
0answers
92 views

Multiple TCP port requirement for a client-server relationship

I designed a basic C# TCP sever that listens on some port. I extended this into 4 other servers that perform very different tasks, but together make up one product. The client needs to connect to each ...
57
votes
5answers
5k views

Why would you not use the 'using' directive in C#?

The existing coding standards on a large C# project includes a rule that all type names be fully qualified, forbidding employment of the 'using' directive. So, rather than the familiar: using ...
3
votes
2answers
234 views

Deep SQL relationships to a C# object model

I have a database with deep table to table relationships for example Clients (one to many) -> ClientData (one to many) -> ClientJob (one to many) -> ClientProcess (one to many) -> ...
29
votes
4answers
4k views

Does C# 6.0's new null-conditional operator go against the Law of Demeter?

The Law of Demeter states the following: Each unit should have only limited knowledge about other units: only units "closely" related to the current unit. Each unit should only talk to its friends; ...
2
votes
1answer
105 views

Pattern for interface between sequence executing object(s) and sequence configuration objects

My motivating case is hardware test automation. We have several different testers (benches of lab equipment that connect to the "device under test" (DUT)), and we write test configuration files which ...
1
vote
2answers
84 views

Throwing exceptions in application configuration providers

Simple question: What is the best/common practice regarding to throwing errors for application configuration providers? Given is a simple key/value-based configuration source: class Configuration ...
0
votes
0answers
77 views

Enforce No Multiple Async Entity Framework Operations

We are working on a large-ish MVC web application with multiple backing stores including a SQL Server database accessed via Entity Framework 6.0. We are using asynchronous operations wherever we can, ...
3
votes
1answer
170 views

Cleaner Windows Forms

Backstory: I am working on a Wizard Setup project and I've ended up with a very big(a lot of lines of code) Form class. Because my form holds a Wizard control which in turn has lots of pages and each ...
4
votes
1answer
775 views

Why is there not a basic SortedList<T>?

As far as I know, there is no way to get a List<T> with the capacity to sort itself. If I add a element, I want the data-structure to insert it in the right position (based on the associated ...
1
vote
0answers
108 views

ASP.Net MVC - Implementing a Test Environment

I would like to implement some sort of test environment for ASP.Net projects. I am trying to implement this as an alternative to mocking the entity framework. Here is what I am trying to achieve : ...
2
votes
2answers
225 views

Using a private auto-implemented property vs. a private field

If I have a need for simple, private fields, is there any reason I shouldn't just make it a convention to use private, auto-implemented properties instead? For instance, I could do this: private ...
0
votes
0answers
97 views

Should I be using a design pattern when creating these objects?

I have a lot of duplicate code in my program that basically follows this structure: If condition is true Create ErrorRecord object Call ThrowTerminatingError(error object) End if The ...
2
votes
2answers
122 views

Making a security on webapi for browser usage [closed]

I have a webapi project working in production for few months now. The entire webapi is server to server. There is a need now to have the same functionality in a browser, meaning the customers ...
0
votes
3answers
177 views

Update XML file versus overwriting XML file [closed]

I have a console application that will make modifications to 1200 systems remotely using SCCM. One of the items to be modified is a GUI menu app that is XML driven to display buttons that launch other ...
5
votes
1answer
196 views

Overriding == for immutable collections

Suppose I have a class that is a readonly collection or immutable objects, e.g. public class ReadOnlyInts : IReadOnlyCollection<int> { private readonly IReadOnlyCollection<int> ...
1
vote
0answers
67 views

ModelState Validation vs JQuery vs Remote

I was stuck with some validations for quite a while. I have been thoroughly searching the internet to find ways to apply the validations I require. I came across many methods for validations even ...
6
votes
1answer
260 views

Never using Models, only ViewModels

I'm starting a new MVC 5 project from scratch. I'm using EF 6 (Database First) and Identity 2.0. My solution consists of 3 different projects: Data (where I have a .edmx and my DB context), Resources ...
0
votes
0answers
26 views

How can I cleanly handle a several permutations of Resource Request, (Optional) Login Control, Resource Result?

Whenever a user interacts with a resource while not logged in, I need to: Redirect them to a secure page. Show a signup/login dialog (which is usually partially customized based on the resource, ...
2
votes
3answers
324 views

Which C# data structure should I use to quantify this information?

I am attempting to determine which data structure I should use for the following information: ("Water", 100F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, ""); ("Tuna", 60F, 184F, 30F, .01F, ...