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

0
votes
0answers
25 views

Syncing file data and form data uploaded at separate times

I have a web application where users can upload office documents. In addition to uploading files users also specify extra information about them that's not contained in the files themselves but is ...
0
votes
1answer
54 views

Sequence of Integration Test in Build Process

We are developing a Web API (ASP.net, C#) project and use Bamboo CI for our continuous Integration. We run the Unit test before the deployment task so that deployment does not happen if test fails. We ...
0
votes
0answers
36 views

Tracking a program-wide state of tasks being done and making it testable

I have a program which does some processing which can be asynchronously requested (WCF). There should be only one computation per identifier (always supplied upon request). So if at some point work is ...
4
votes
1answer
108 views

Overflow Exception Checking Problem

Background I have to call a method that needs to return a signed integer (see code block below) after converting from an unsigned integer. The reason for this is that I have to do bit-wise math that ...
2
votes
1answer
70 views

Does murmur3 hash have memory?

This implementation of Murmur hash yields different results when called twice in a row: Murmur3 m3 = new Murmur3(); var la = m3.ComputeHash(new byte[] { 1, 2 }); var lb = m3.ComputeHash(new byte[] { ...
5
votes
3answers
389 views

Is it ok to have a class that only has boolean properties?

Scenario We have a class Vehicle, this class contains some properties to define the object such as a CarBrand, TransmissionType, Color, etc.. A car (vehicle) also has options, these days a lot of ...
1
vote
2answers
89 views

Catching exceptions from child process

I am looking for any info. (I know some C++ with win32 and C#) The Idea: The idea is to help a program with missing files load. In the end I wanted to see if I could have my program launch a simple ...
-3
votes
1answer
144 views

C# Share Datatable in Multi-threading

I am beginner in Multi-threading in C# & confuse in current task. My task is to read datatable and display datatable in C# console application using multi threading. I have three threads and one ...
0
votes
1answer
373 views

Strange C# method call syntax

Can you explain this method call syntax to me? this.mainParticleSystem.Simulate(time, withChildren: false, restart: true); Particularly I don't understand what withChildren: false parameters syntax ...
0
votes
3answers
151 views

What is the best way to update boolean variable in this particular scenario? [closed]

I have the following class and a method named ValidateEverything(), where IsEverythingValid becomes true only when a or b or both of them are true. I was wondering about what would be the best way to ...
2
votes
0answers
75 views

Creating a generic Cache solution for function calls using SOLID principles in C#

I would like to have a caching solution for a variety of function calls. All of the function calls fit the following signature public ResponseType ProcessRequest(RequestType request); About half ...
4
votes
1answer
114 views

Using delegates as named lambdas

Suppose we have a domain in which we can generalise some operation by passing in a function, like the Select \ map functions. Now suppose that the function we pass in has some domain specific name, ...
-2
votes
1answer
46 views

logging for an web application deployed on multiple nodes

My production setup involves four servers running behind load balancer. I have same set of web applications deployed on all four servers. The log files generated on one server are completely isolated ...
7
votes
2answers
406 views

When and why to use Nested Classes?

Using Object Oriented Programming we have the power to create a class inside a class (a nested class), but I have never created a nested class in my 4 years of coding experience. What are nested ...
96
votes
16answers
14k views

Should I add redundant code now just in case it may be needed in the future?

Rightly or wrongly, I'm currently of the belief that I should always try to make my code as robust as possible, even if this means adding in redundant code / checks that I know won't be of any use ...
1
vote
1answer
76 views

Split class into two or leave as one

I have the following class: internal class LeaveRequest : ServiceBase { private const string InvalidRequestMessage = "Specified Request does not exist"; private const string ...
0
votes
1answer
51 views

Retrieve variable from Console.ReadLine()

I am making a tic-tac-toe game in C#. I have a string variable for each square. I want to make it so the user inputs the square name i.e. (topMiddle). Then I declare the input playerInput. I want to ...
3
votes
3answers
194 views

Optimal way to use null conditional operators in boolean expressions

You are writing a boolean expression that might look like this: team.Category == "A Team" && team?.Manager?.IsVietnamVet public class Manager { public bool IsVietnamVet { get; set; } } ...
5
votes
1answer
105 views

Partially parallel producer-consumer pattern with internal state

I need to implement a producer-consumer pattern for reading, processing and saving electrical values. I have to implement this in C# .NET 4.6.1. I try to describe this in great detail, so that there ...
2
votes
1answer
134 views

Developing a calculator using the command pattern

In an attempt to solidify my understanding of the command pattern, I decided to write a calculator application that utilised it. After making some progress, I realised that my choice of application ...
4
votes
1answer
160 views

Am I using the factory method design pattern correctly, or which creational pattern should I use?

I've been studying creational design patterns for the past week or so because I have a common use case that keeps coming up, and I can't figure out which pattern fits the bill. Here is a simplified ...
-1
votes
3answers
215 views

Is there any technical reason to be concerned with casting speed?

So, I'm working on a project that takes a very complex entity from a third party framework and converts it into the native object that defines that entity. This entity has several one-to-many ...
0
votes
0answers
40 views

Where to store DataSets in this project?

I'm currently running a structure like this in my C# project: .Classes (This is where I store my classes) .UI (WinForms) .Helpers (Utility classes and extensions) .Reports( .rdlc reports) Now I'm ...
0
votes
0answers
45 views

Centralized management of app.config parts for self-hosted .NET services

What will be the best way to handle these scenarios, if they are not one-time, but regular: Self-hosted services on quite a bunch of machines are needed to be reconfigured to a different database in ...
4
votes
2answers
169 views

Can StringBuilder be used to effectively store and manage multiple variables of data?

Using C# I want to create one or more text files to store all the data pertaining to a particular 'Thing' on the same line. I am presently leaning towards StringBuilder as per the following. ...
2
votes
4answers
120 views

Are names like OrderCreation and UserRegistration suitable names for business logic / domain classes

We have moved to a more SRP model and found coming up with class names challenging. Previously we had a Order class that looked something like this: public class Order { public void Create() ...
3
votes
8answers
722 views

Why can't we just use variables instead of constants?

I can't see the point of constants. For example I can use the famous example of PI: PI = float(3.14) Here I get the job done without a constant. Who cares if the value never changes during the ...
2
votes
2answers
109 views

Should we add an extra class to this code sample

I have a shopping website which allows users to place orders. In my web application when the users click 'Create Order' i call an OrderService class which looks like the below: public class ...
1
vote
3answers
111 views

What should be in my business logic class

We are currently having an internal debate on how our business logic classes should be structured. At the moment we structure our business classes like this: public class OrderBL { public void ...
1
vote
1answer
162 views

What could be the better c# design for following requirement? [closed]

I am working on creating a c# design for following requirement. I am creating this for a fitness website. I have an article (as Text) and a exercise (as Image or Videos) as the base entity. Now i ...
1
vote
1answer
205 views

Why use Razor Syntax?

Was doing some reading today about Razor Syntax with MVC Framework and was wondering why would/should I use Razor? What benefit does it provide over doing the same thing in the code behind and/or ...
3
votes
1answer
67 views

Within an interface specified by a core component, should it request IReadOnlyCollection or IEnumerable?

In thinking about the principle of "be conservative in what you send and liberal in what you accept", I generally try to make my methods receive IEnumerable parameters, but emit a IReadOnlyCollection ...
3
votes
2answers
172 views

Best Practice for masking Credit Card informations in Web Api 2

In an Asp.Net Web API 2 project, We're logging every http request and response with log4Net. Some controllers have critical parameters such as "CreditCard, CVV, Month, Year" etc. This data should not ...
2
votes
2answers
230 views

Best practice for using StringBuilder

I'm writing a camera control program which uses many methods for each of the different commands. One example is: public void CameraPan(int Id, string Direction, int Speed) { StringBuilder sb = ...
1
vote
1answer
88 views

.NET Implementation Question (repository access)

I am trying to write a generic method which goes a particular DB table depending on the entity which is passed (all valid entities implement IStaticData) : IEnumerable<T> ...
0
votes
0answers
33 views

Should I reference both up and down a hierarchy when using Entity Framework?

Let's say I'm modelling an organizational hierarchy which consists of Divisions that contain Departments that contain Teams. So Division -> Department -> Team. While it makes sense for the Division ...
2
votes
1answer
121 views

Are nested private classes considered composition?

Background I am considering a design that includes a public API class containing many nested private classes. I am doing this for the following reasons: Why private nesting? They will have no use ...
1
vote
1answer
119 views

Is a an object Necessary or can I still use a DataTable

I'm currently working on a fund project and I have it set up so I get the holdings from my database and store in in to a DataTable to process. I've created a function where my Database results are ...
19
votes
5answers
4k views

Is it okay for a class to use its own public method?

Background I currently have a situation where I have an object that is both transmitted and received by a device. This message has several constructs, as follows: public void ReverseData() public ...
0
votes
1answer
74 views

How to call a specific element in XmlReader

You know that XmlReader reads like crazy and doesn't care about root element or anything, it just reads line by line on every element. My XML file is a student list with some of their data so ...
2
votes
2answers
155 views

Developing a new application on a restricted time [closed]

Me and my colleague are working on a new application that should replace as soon as possible an old VB6/Access 97 application made years ago.This application has a lot of problems, adjusting them in ...
2
votes
2answers
294 views

Modeling a multi-channel communication device in C#

Background We (my coworkers and I) are architecting a high level C# API to interact with a hardware device's native Windows DLL. First I will discuss the hardware-architecture, then get to the ...
1
vote
0answers
68 views

Guaranteed message sending for messages of different priority for different modules

We have created a message que system using priority messages. The idea behind this is as follows: We have a list of clients. All clients know if (and what kind of priority) messages they have ...
1
vote
0answers
55 views

Idiomatic way of uploading images using async to Sharepoint from ASP.NET 5

Another title could be 'How to make an async Repository pattern with image upload in ASP.NET 5' I'm making a site with ASP.NET 5 and it uses the CSOM (ClientContext, etc) to connect to a Sharepoint ...
2
votes
0answers
51 views

Merits of DI, Abstract Factory implementation review

I'm writing a brand new system and trying to stay true to the SOLID principles, specifically Interfacing and Dependency Injection. We are sticking closely to the Microsoft stack so we are using C# ...
5
votes
4answers
381 views

Avoiding hangs when calling a native API

Background We have a piece of programmable hardware here at work that we integrate into almost all of our systems. This piece of hardware came with a native Windows DLL (for which we do not have the ...
0
votes
3answers
195 views

What to do if I need more than one base class in C#? [closed]

Let's say I have a grid with square fields. For the fields I have an abstract Field class. This class has several subclasses, for example EmptyField or RoadField. Some of these fields can be connected ...
6
votes
4answers
262 views

How to separate public and “mostly private” code in C#? (Friend classes, PIMPL pattern, etc.)

Reminder: If you have tips, please remember to put the reason objectively, such as "having two distinct SetInt() functions in the same file violates reader expectations that they'll be overloads, and ...
2
votes
0answers
54 views

Data pipeline with fallbacks and callbacks

I'm refactoring our current design for how we download static data. It's a mess of deep class hierarchy and callback hell and I want to convert it to a more elegant straightforward design. Here are ...
1
vote
0answers
112 views

Implementing software licensing

I have an unpoliced piece of software and I must implement some control over who can install it via licensing. I already have an authentication server that implements OAuth 2.0 and OpenId that's used ...