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

1
vote
2answers
443 views

How to solve this inheritance problem

I have the following classes: public abstract class StaticFileController<File, QueryData> : AsyncController { private string _resourceName; public StaticFileController(string ...
-1
votes
1answer
118 views

Program uses an older version of dll rather than the one embedded in the exe [closed]

I have a project for which I used to deliver an additional .dll file. At some point, I have installed Costura.Fody package and started embedding this .dll in the .exe file to get a one-file standalone ...
2
votes
2answers
221 views

Await state async

For speed we sometimes return response to consumer before state is saved in DB. Sometimes (Mostly for our automated consumers) this can break because the want to make actions on the saved data before ...
1
vote
2answers
273 views

Understanding a project architecture

If I develop an application, I'll often use a project structure like this: MyApp.DataAccess.Implementation MyApp.DataAccess.Contract MyApp.Business.Implementation MyApp.Business.Contract ...
1
vote
1answer
217 views

Code First Approach and Business Classes Validation

I have a solution split into two projects : A class library containing all of my model classes (lets call it Business), and an ASP.Net MVC project. My Business classes are meant to be generic and ...
-1
votes
1answer
149 views

Programming Pattern - Single Data Structure - Multiple Methods [closed]

I have a single data structure that holds a relatively small amount of objects (ca. 1500) and several methods that are acting on it. Is there a programming pattern to iterate the methods over the data ...
14
votes
4answers
4k views

Why is .NET VM based? [duplicate]

Java has been designed to run on a virtual machine to allow portability for programs. However .NET has been designed from the start specifically for Windows. Than what is the reason for .NET ...
1
vote
2answers
152 views

Performance concern in object oriented languages [duplicate]

I recently moved into web development using ASP.NET MVC. The language I use is C#. Having considerable experience in C makes me look for optimized coding standards (memory, efficient data structures ...
19
votes
1answer
844 views

What are the standards for dealing with pluralia tantum in your code? [closed]

When using variables of which their plural and singular are both the same, how do you name them? Are there any standards out there? For example: Series[] series // Plural Series series // ...
3
votes
3answers
91 views

How to design access to different type objects in protocol response

I have written a communication library for an industrial device protocol. The response frame contains a byte array as payload data. The payload data consists of several "objects“ of different types, ...
2
votes
5answers
175 views

Creating variations of a property heavy class

What kind of pattern or design can prevent the creation of a class packed with properties that aren't always used? Example class Car{ public string type; public string name; public DateTime ...
6
votes
2answers
372 views

How to populate Lazy object from database

I have these classes: public class Order { private Lazy<IEnumerable<Volume>> _volumes; long ID { get; private set; } string Description { get; private set; } ...
-2
votes
4answers
317 views

In C# Is using private constant strings better than using strings directly in the code? [closed]

Consider the following two cases: case 1: class A { private const string MyConst="Hello"; internal void CallMe() { System.Console.WriteLine(MyConst); } } Case2: class A { ...
2
votes
1answer
148 views

Common Repository design

What I have: I am developing an Active Directory layer which will be used by a huge application with several modules having several solutions and projects... I am fairly new to developing large ...
3
votes
1answer
311 views

Onion architecture in client-server application

I'm staring new project, cross-platform. I want to use onion architecture there. It will be a simple game (tic tac toe), just for education purposes. This app will be client-server type. Now, I read ...
4
votes
1answer
195 views

How is one supposed to deal with the intermediate buffer of DataReader class?

Summary I am developing a WAV file format reader under WinRT, and for this I need to read random amounts of structs consisting of fundamental types such as int, uint, float and so on. Back in ...
0
votes
1answer
358 views

Improving performance with caching of files in C# [closed]

EDIT: You were right, the problem is not checking if a file with the same name exists but the connection. I made a mistake measuring the time with StopWatch and included a part which used the network ...
4
votes
2answers
196 views

How can I write a flexible messaging structure for sending TCP messages to clients and server

The general question: how can I write a flexible, but not property heavy, messaging structure for sending TCP messages to clients and server? Example: I have a TCP Server for a game that sends some ...
1
vote
1answer
347 views

C# DbContext with nested classes containing the Repository methods

So I have done a lot of reading and it appears that, since DbContext already implements a repository and unit of work pattern combination, creating more abstraction classes would be redundant. ...
1
vote
1answer
98 views

Azure BLOB grained access

I have a standalone WPF desktop application which gathers data from Digital-to-Analog converter boards, computes, analyzes this data and then it creates binary files (proprietary format) with the ...
2
votes
3answers
94 views

How to consume standard routed API in a clean way?

Let's take an example of a generic API endpoint that looks as follows: https://api.imgur.com/3/gallery/{section}/{sort}/{window}/{showViral}/{page} Conditions on this endpoint are as follows: ...
29
votes
6answers
2k views

Advantages of using .dll files over linking .cs files to projects (for my own generic helper classes / extension methods)

I have a helper project which I use in all the applications that I create. It contains some extension methods and a bunch of generic helper classes, controls etc. I update/extend the helper project ...
3
votes
4answers
469 views

Why can't I call a constructor in itself?

I am currently porting the class NumberRange from Java to C#. I am writing this constructor and I wonder whether I can call a constructor in itself. Something like this: public NumberRange(Double ...
0
votes
1answer
154 views

How to design a database schema for a multi-user To-Do application in Azure?

I want to create a windows 10 universal to-do app with offline sync capability. So I checked out this tutorial which helped me to get started on the offline functionality. But I was wondering how ...
-1
votes
1answer
179 views

process large dataset c# [closed]

I have an application that process portfolios. I must aggregate 8 years of returns of aproximatelly 8K securities. (about 2016 doubles (8 years of data) for 2 dates (for comparison) 4032 for 8K ...
5
votes
2answers
659 views

Foreach loop and variable initialization

Is there a difference between these two versions of code? foreach (var thing in things) { int i = thing.number; // code using 'i' // pay no attention to the uselessness of 'i' } int ...
2
votes
2answers
172 views

Maintaing drop down lists for the application

What would be the best approach to maintain the dropdown lists for the whole application (like city, state etc) taking into account the SOLID principles and performance? Right now am loading the list ...
5
votes
2answers
321 views

Sending Exceptions as event arguments

Is it a good idea to send Exceptions as EventArgs in C#? (And not actually throw the Exception). I have a class that performs a long running asynchronous task. If something goes wrong in the middle ...
31
votes
1answer
4k views

DRY unrelated, but nearly identical, code

I have some code that is nearly identical, but uses absolutely different types, with no inheritance between them, on the main variable. Specifically, I am writing an analyzer with Roslyn for C# and ...
21
votes
5answers
4k views

What's the use of .Any() in a C# List<>?

I've been discussing this with colleagues, and we couldn't figure out what the use is of .Any for any given List<>, in C#. You can check the validity of an element in the array like the ...
2
votes
3answers
306 views

Manual Dependency Injection Examples Still Tightly Coupled

I've been using AutoFac for some time now to take care of the dependency injection we're using in a web project. All is well, but I now want to demonstrate DI outside of an AutoFac context for reasons ...
5
votes
2answers
517 views

Why override a static method of an abstract base class?

I'm working on C# code where a static method of an abstract base class is being overridden by the class that inherits the base class. Why is this being done? I thought that only a virtual method of an ...
0
votes
0answers
189 views

I just want to clarify things about the behavior of Session in Asp.Net MVC

The reason why I asked this is because I want to know the basic principles about the behavior of a Session object. I'm working with session variables right now and I understand that it has a major ...
4
votes
2answers
169 views

Fix a leaky abstraction (type checking)

I have a method that accepts an interface and does type checking on the parameter, and depending upon the type a decision is made to either send an email or an alert public void ...
2
votes
2answers
833 views

Strategy to avoid running out of memory in memory intensive application

My C# .NET application has to read lots of files with electrical readings. There are several calculation to be done and output files need to be generated. Due to the nature of the input it would be ...
3
votes
1answer
70 views

How do I Balance Multiple Service Contracts with Duplicate Structures

My current task requires me to use a set of web service calls to a 3rd party vendor in order to retrieve and update information. The objects used in these calls - namely the response from a get and ...
0
votes
1answer
104 views

ASP.NET synchronous commands handlers

A question about DDD, for validating a Proof Of Concept. Let's say we have a webpage that triggers a Domain Event. For instance, updating the status of a client after an interaction occurred on that ...
2
votes
2answers
109 views

Relating an array of objects to an enumerator

How would you relate the indexes of an array to an enumerator without leaving the chance of mismatch? Example public enum difficulties { easy, medium, hard } public List<Lobby> ...
12
votes
2answers
496 views

Is creating a new List to modify a collection in a for each loop a design flaw?

I recently ran in to this common invalid operation Collection was modified in C#, and while I understand it fully, it seems to be such a common problem (google, about 300k results!). But it also seems ...
1
vote
3answers
284 views

C#6: Should I refactor my code using Resharper for the new features? [closed]

C# 6 is here for a while now and brings with it some syntactic sugar that Resharper is kind enough to highlight and recommend that I "migrate to". Should I apply these fixes automatically to the ...
2
votes
1answer
345 views

Help understanding modeling in domain-driven design

I've been trying to learn domain-driven design (and similarly Onion Architecture) the last week or so. I think I've got an understanding of it, but like math, I suck at extracting all of the ...
20
votes
1answer
1k views

Why do arrays in .Net have Length but other collection types have Count? [closed]

In C# for example, arrays have Length property. But other collection types like lists, etc. have Count property. Is there a reason why these two are different? If so I would like to know.
2
votes
1answer
158 views

C# try/finally for state cleanup

Is there any reason (for instance: performance) against moving state "cleanup" code in a finally state? Example: this.state.InProgress = true; // logic here this.state.InProgress = false; With ...
2
votes
0answers
104 views

Separate settings and implementation class hierarchies

We use XML serialization to store class settings. Each setting-class has (but doesn't reference) corresponding implementation-class. Therefore we can easily make a "settings dll" without any ...
1
vote
1answer
101 views

Does ReaderWriterLockSlim provide thread safety and speed efficiency (compared to a traditional lock) when using a List?

I have a list, to which I write once in every update Loop and then I spawn some tasks which create read that List and create a duplicate to manipulate that data. More or less it's List.ToList() call ...
1
vote
1answer
108 views

How to create a re-usable, command based messaging system

I am having trouble writing a simple command based system for a chatroom. I want users to be able to do chat actions such as /j myChatRoom or /join myChatRoom /w user12 Hello or /whisper user12 ...
4
votes
2answers
253 views

When is it appropriate to use expression bodied members? [closed]

C# 6 introduces expression-bodied members, which allow for simplified code in methods and properties that only return the result of an expression: public override string ToString() { return ...
1
vote
0answers
346 views

Integrate C++ DLL with C# GUI asynchronously (design issue)

This is more a design than an implementation question. I am aware of how to integrate a C++ DLL within a C# main app that acts as GUI. Believe me that I've read all other questions on similar topics, ...
4
votes
4answers
311 views

Should an application configuration interface be broken into multiple interfaces to reduce feature creep?

My windows service is neatly separated into 5 components - each with their own interface and pulled together by a bootstrapper. One of my requirements is to provide configuration options in my ...
8
votes
6answers
2k views

How to implement a property on class A which refers to a property of a child object of class A

We have this code which, when simplified, looks like this: public class Room { public Client Client { get; set; } public long ClientId { get { return Client ...