C# is a multiparadigm, managed, garbage-collected object-oriented programming language created by Microsoft in parallel with the .NET platform
2
votes
3answers
184 views
Why does C# not allow scope-local using Directive?
One thing I do not get with C#'s using Directive is why I can only "use" a namespace at file level, and not within any arbitrary block scope.
(using namespace x; of C++ does allow this and certainly ...
0
votes
0answers
55 views
What to use in case of waiting for something that is complete: delegates, events and/or thread
I try to give a concrete example.
Create a semaphore for a crossroads.
I have two semaphores. I have possibility to set a duration of semaphore 2 minutes, 5 minutes, 10m inutes etc.
When one ...
2
votes
5answers
202 views
Constructor overloading or allow null?
Which is the preferred design to use, one constructor that allows null, or two constructors where one throws an ArgumentNullException on null?
Two constructors with exception throwing
public class ...
0
votes
3answers
66 views
Using nested private class to hold data from csv file
I have a class that only has one method. This method has to read csv file, do some work concerning internal logic (check if item already exists, do some transformations, etc.) and finally write all ...
0
votes
0answers
22 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
32 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 ...
-2
votes
2answers
69 views
What tools and technologies to use for cross-platform app [on hold]
I have started a small project and I wanted it to be cross-platform. It is a simple chat app that would need to work on Android, iOS, Windows and web. Now I did do a bit of research on this topic and ...
-1
votes
0answers
39 views
C# Asp.net Client/Server WinForm Application
I am having a little trouble getting my head around a university assignment for programming.
We need to make a client/server application, which uses a database. I have a server (Which is created ...
-4
votes
0answers
32 views
Event listener for a message/warning box
I am working on a solution where I am refreshing Excel files with Interop. Some of the Excel files have some kind of errors, and thus displaying an alert that something is wrong. Is there any way to ...
0
votes
0answers
32 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
82 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 ...
-5
votes
0answers
24 views
Search a string item from a text line in listbox [closed]
I have a textbox which contains items separated by comma.
I want when the user find a text it should return,
my code just find the first item in the string,
example:
dan,john,25778,ok
When a user ...
2
votes
1answer
61 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
353 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
73 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
79 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
352 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 ...
-1
votes
0answers
40 views
C# 3D model display for Robotics
I am currently working on designing a robotic arm for a variety of low cost applications.
However I am stumbling at the point of developing some software to show the robot arm in movement on the ...
-3
votes
0answers
51 views
Get Landline code from regioninfo [closed]
I have a database with two digit country codes. For example "NL" or "US".
And I get de regioinfo with:
RegionInfo region = new RegionInfo(input);
I can see in RegionInfo the landline code which is ...
-2
votes
0answers
49 views
Trans-compiler to convert a C code to C# code for a specific set of APIs [closed]
Is there a way to write a trans-compiler to convert a C code to C# code for a specific set of APIs. Like, I do not want to write a translator for the conversion of entire programming language ...
0
votes
3answers
150 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
66 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
105 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
38 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
359 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 ...
93
votes
16answers
13k 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
70 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
40 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
162 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
83 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
120 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
146 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
207 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
39 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
29 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
160 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
116 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()
...
2
votes
8answers
659 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 ...
0
votes
0answers
68 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
100 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
160 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
votes
0answers
46 views
Architecture for a C# data collector
I want to write a C# application that does the following things:
Receive tick data on different Named Pipes (from Metatrader4)
store that data in a data structure (Separately for each pipe, but all ...
1
vote
1answer
176 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
59 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
144 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
208 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
81 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
32 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
117 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
107 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 ...