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
votes
2answers
202 views

Why use using-statements when you want to reopen connections? [closed]

In a Winforms project I've been working on recently, I've been dutifully using using-statements for objects that implement IDisposable. I want to reopen a database connection, however because the ...
0
votes
1answer
205 views

Simplifying code of a calculator (help) [duplicate]

This is part of the code of a calculator that works on command line. It works fine and the math is correct but it's a little redundant: switch(Operator) { case "+": result = num1 + num2; ...
0
votes
1answer
51 views

MSDN - ServiceLocation Outdated Why? Alternatives?

I recently (1 month) start working in a project and as I was going through the code I saw an using Microsoft.Practices.ServiceLocation and as I searched for the documentation on that library is says: ...
2
votes
1answer
45 views

ADO.NET - Is it better to handle a combo box or label event, and where should the data be sourced from?

Context I recently wrote a final exam that required using a BindingSource object with ADO.NET to populate a number of combo box and label controls from which the user could perform basic business ...
1
vote
3answers
118 views

How do you create immutable objects with many parameters?

I need to create an immutable object but it requires several parameters to work like: class FooRepo { public string ConnectionStringName { get; } public string SchemaName { get; } public ...
0
votes
3answers
169 views

Does IEnumerable required to use foreach in collections

I have following class that didnt implement IEnumerable but working perfectly with foreach. And also , arrays are working without implementing IEnumerable. So why it is keep saying that IEnumerable ...
0
votes
0answers
36 views

Custom C# Script and Security using CodeDom

I'm making a piece of rendering software and I want to make the tools it encompasses extensible. I've built a UI that lets the user write custom C# functions for blending values. The functions (and ...
-4
votes
1answer
81 views

User Interface and code. How they communicate? Is it just an image and nothing to do with program code [closed]

Does UI interface is just an Image created by graphics tools?. I need to know that when a user interface created to read an textbox in c#. When a text entered is it take values from keyboard by ...
0
votes
0answers
28 views

Bi-directionally synchronize/mirror folders over the internet

I am programming on the C# stack, but I have next to none Azure experience. We have several customers who have various processing needs on data files that reside at the customers computers. We want ...
0
votes
0answers
26 views

creating a teartown in integration test by deleting the test database and load the mdf again

I had a Friday developers debate with all my smart colleagues about Tear down process in Integration testing. They are putting a debate that getting a new database mdf file is better while during ...
5
votes
1answer
270 views

How to move from OOP object composition to FP function composition in C#

I have been working for a few weeks on a new web project and I am realizing that all I am doing is basically calculations and transformations on data, and that most of my classes do not contain any ...
1
vote
3answers
67 views

Use HttpUtility.HtmlEncode or create extension method

Should I use HttpUtility.HtmlEncode or write an extension method? Pro for using HttpUtility.HtmlEncode is that other developers can instantly see and recognise what it's doing. Pro for using an ...
1
vote
2answers
142 views

Is an empty class in some cases correct

I know it's generally a design flaw to have an empty class, yet I'm wondering whether there are some cases where it isn't to have an empty (abstract) class to group objects. Especially when ...
1
vote
3answers
269 views

Business rules design pattern?

I'm working on an interface for implementing business rules in order to improve SOLID-ity; so I can move a lot of logic out of Web API controllers and into a business library. The Common Problem being ...
0
votes
6answers
511 views

Is it easier to read and maintain code using “!” characters, or implying “Not” in the method name?

I often find that "!" characters (meaning "not" in C-based languages) are easy to overlook. So I sometimes create methods that return the inverse result. For example, instead of doing this: if (!...
1
vote
3answers
297 views

Put code on client (JS) or server (C#)

In an ASP.NET app, I've got to decide whether to put a complex piece of code on either the client in JS or on the server in C#. I've considered performance (if on server, it would be a small ...
1
vote
2answers
231 views

Most efficient method for large switch statements

Let's say you have many paths that an application can take at a certain point based on the value of a specific input (for example a simple int). Is there a certain method that is most efficient for ...
0
votes
0answers
29 views

Background layer for e-mail actions

My application features an e-mail layer (IEmailHandler) that implements various protocols (via IImapHandler, IPop3Handler etc.). Now when the user logs in, we fetch all their e-mail accounts (could ...
-2
votes
1answer
150 views

Is it better to learn a new language or a high level application of a known language [closed]

Recently I got chatting with my C# .NET professor and mentioned that over my free time I was learning Rust and it's been very interesting. To this the prof suggested me to not waste my ...
2
votes
3answers
115 views

Why aren't properties implicitly convertible to delegates

We all know that properties in C# get compiled to actual plain old methods. But unlike method(-group)s, they can't be given as arguments to other methods excepting a delegate like a Func<T> or ...
4
votes
1answer
164 views

What are the important considerations when switching from monolithic to microservices architecture in .NET?

We are contemplating breaking up our monolithic monsters into microservices based architecture progressively. We have 5 teams, each team containing 2-3 C# developers, at least 1 database developer, ...
-1
votes
1answer
172 views

What's the best way to populate a new row in a database?

Is it possible to add a new row to a database using DataSet? When I created a new DataSet and dragged the table from the database I could see that in the DataSet methods there was one called insert ...
1
vote
1answer
90 views

Send messages from multiple services/application and display them in one place

Inside system I'm developing I have several Windows Services, couple of applications running in Scheduler and COM+ application that is running my custom DLL's. Some of them are running on same PC, but ...
1
vote
2answers
112 views

Private fields and encapsulation

I'm reading the head first c# book and don't quite understand what this means. "Any class can see private fields in another instances of the same class"
2
votes
1answer
112 views

Different ways of array declarations in C#

What is the difference between the following two methods of creating an array in C#: int[] arr = new int[] { 1, 2, 3 }; Array arr = new int[] { 1, 2, 3 };
-1
votes
1answer
31 views

Language cross platform that allows different socks connection per thread

Hello i'm developing an app that needs to do many requests with different socks connections. I was doing it in C# but i'm not sure how well it will work on a linux server even with .net core . Java ...
0
votes
0answers
25 views

Abilities interacting with aspects of other abilities - how to implement efficiently

In my game I want characters to be able to cast spells which deal a certain amount of damage of a certain type to other characters in the game. I also want abilities that negate an amount of damage ...
3
votes
1answer
136 views

What is the correct way to test performance of methods?

I made a few classes for processing and validating data in xlsx and csv. However, I am curious in testing how fast the methods I wrote in C# for the heavy lifting are. Here's what I currently am ...
2
votes
1answer
117 views

Event subscription in finally clause

Background My program communicates with a device that is usually asynchronous, but can sometimes behave synchronously. I have an event handler that I use for receiving the data asynchronously, then I ...
0
votes
0answers
14 views

JPA: Property/encapsulated objects instead of fields

I'm moving to JPA (JavaEE, Eclipselink) from a very large C# project. The classes were not using simple fields but Property objects. Example: //C# public class State : DataObject<State> //base ...
0
votes
0answers
78 views

Can I keep my code loosely coupled with public-facing enums?

I have some enums in a concrete API/library that will be publicly used by application projects. My problem here, is that I cannot write an interface to these enums (that I know of). I should have ...
2
votes
1answer
118 views

Where do you print IO error messages from in a console app?

I'm writing a simple console app to rename a bunch of files/folders, and I want to design this console app to be as modular as possible. The console app is as simple as it gets: Ask the user what ...
3
votes
2answers
95 views

How should I refer to data bound columns?

I work often with data-bound applications with WinForms; records are pulled from a database and updated in a client application that I write. Stored procedures are used for all database transactions ...
3
votes
4answers
247 views

Class Library - How to communicate between objects that are not aware of each other?

I am trying to improve my programming skills and knowledge and I have been doing some reading about various design patterns and youtubing videos etc. One subject I thought was interesting was about ...
4
votes
1answer
123 views

Why generic interface cannot implement dynamic type?

If it possible: IList <dynamic> = new List <dynamic>; or: class A <T> { A(T){} } class B: A <dynamic> {} . Why it is not possible to do this: class U: IEnumerable <...
1
vote
3answers
119 views

Same class and namespace name

I have a problem how to go about naming my namespaces and classes. I already figured they shouldn't both have the same name, as it causes all kinds of problems. Most notable problem for me is that I ...
0
votes
1answer
72 views

IoC, Unity: Creating a component with additional concrete parameters

I am struggling with the following issue. Let's say I have a component that performs operations on guests and rooms, and uses a number of abstract interfaces, along the lines of: class HotelManager { ...
0
votes
1answer
93 views

Why is ImmutableDictionary<TKey, TValue> implementing IDictionary<TKey, TValue>?

It looks like a weird design choice, because a Dictionary and an ImmutableDictionary are quite different write-wise. (Read-wise, they both implement IReadOnlyDictionary, which is fine*) In fact, the ...
4
votes
1answer
111 views

Monitor.Enter() when a thread is of highest priority

Background Okay, so let's say I have some high priority (ThreadPriority.Highest) thread t which needs to enter a critical region in order to consume some data. I will use the following code snippet ...
7
votes
1answer
409 views

I need to be able to adapt my type to theirs, and theirs to mine

I have a situation where I have an external library. In short, I need to be able to adapt my type to theirs, and theirs to mine. The library has a collection like so: interface IExternalCollection { ...
0
votes
0answers
16 views

Should I recreate entity of proxy or inherit it?

I am using an external service, which is referenced as a service. There is an auto-generated entity User, and I can easily acquire it using proxy client: [System.CodeDom.Compiler....
1
vote
2answers
120 views

Will it be okay for an interface to take a dependency on an interface in this situation?

Background I have an interface defined for a circular-buffer called ICircularBuffer in a separate project. This ICircularBuffer is something that we use all over the place, so it resides in the ...
5
votes
3answers
153 views

Verbose Return Types

I've recently been writing some code that deals with 3rd parties -- obviously errors will happen so I'm using Either/Maybe monads where appropriate. As this is C# I'm also using async Tasks too. My ...
0
votes
1answer
120 views

Sharing information between two independent application

I have to share parameters/information between two independent applications: an Executable and a PDF file. By clicking a button within the pdf I want to perform some specific task (or run code) in my ...
0
votes
0answers
94 views

Should I design my Unit-Of-Work like this?

I am using .net and Entity-Framework (EF) on the back end and I would like some advice on this Unit-Of-Work (UoW) implementation. Should I create a unit of work with one entity and multiple services? ...
1
vote
2answers
116 views

How to do dynamic dimension for loops

I have a for loop in C# as below, int[] dim1, dim2, dim3; //Initialize dim1, dim2 and dim3 for(int i = 0; i < dim1.Length; i++) { DoSomething1(i); for(int j = 0; j < dim2.Length; j++)...
3
votes
2answers
138 views

Creating instances of an interface through a static method

Is the following design flawed? Basically I have a main class used to create an object of a type and then return it as the main interface of the type. The problem with this is that each of the ...
3
votes
0answers
95 views

Generic request processing

I got a webservice that accepts multiple calls that require different handling and validation, using generics I've managed to create a common class that accepts a handler and a validator and it looks ...
-3
votes
1answer
164 views

Any languages where string default value = “”?

Are there any programming languages where the default value of a string is "" ? If so, what are they?
0
votes
2answers
97 views

Injecting a factory with multiple constructor parameters

Initially I needed only one queue to be created by the MessageQueueFactory: container.RegisterSingleton<IMessageQueueFactory>(() => { var uploadedWaybillsQueuePath = ConfigurationManager ...