Questions tagged [c#]

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

7
votes
2answers
1k views

How to maintain a demo version of an application?

I need to be able to demo our production application to prospective clients. The way I have it setup today is simple. The demo application is an exact duplicate of the production system, except that ...
6
votes
2answers
994 views

Where should I put Validation Logic when using CQRS?

I asked this question a while ago: What is the "best" way to apprach validation from the perspective of a DDD purist? At the time I decided to put the validation logic inside the domain ...
6
votes
2answers
9k views

Dependency injection for a library with internal dependencies

Background I am working on a class library in support of a web site. The library combines related APIs from several different vendors, all of which have their own particular nuances and domain ...
4
votes
2answers
931 views

Should a Rich Domain Model have repositories injected in some situations?

Please see the code below, which I took from Jimmy Bogards wicked domain models: public Offer AssignOffer(OfferType offerType, IOfferValueCalculator valueCalculator) { DateTime ...
4
votes
4answers
1k views

Entity Framework and distributed Systems

I need some help or maybe only a hint for the right direction. I've got a system that is sperated into two applications. An existing VB.NET desktop client using Entity Framework 5 with code first ...
3
votes
2answers
621 views

Is there a pattern for non-CRUD operations against a database?

In my very small C# application, I handle the SQL queries directly from the code using basic ADO.NET. I do not want to use an ORM, such as Entity Framework. Now, I have a repository for CRUD ...
-2
votes
2answers
3k views

C#/C++ GUI development without drag and drop? [closed]

I'm currently programming Java, I have played around with C++ before, but I have never touched GUI as I feel "cheat-like" when using its drag and drop system. I feel good and enjoy programming my own ...
13
votes
7answers
27k views

What should I include in my class documentation header

I'm looking for informative class documentation format for my Entity, Business Logic and Data Access classes. I found following two formats from here Format 1 ///------------------------------...
11
votes
4answers
3k views

C# return variables

In a debate regarding return variables, some members of the team prefer a method to return the result directly to the caller, whereas others prefer to declare a return variable that is then returned ...
6
votes
6answers
2k views

How to create a timed-event architecture using a SQL database

The title of my question is general because I feel like this problem is of a general nature, but to set the stage I'm going to provide a specific example. We use a homegrown workflow engine that is ...
6
votes
3answers
1k views

Is it poor practice to have a class implement an abstract class without adding any new fields/members/functionality?

I am writing a wrapper for a REST API and I have run into something I have never had to ask myself before. This API is for E-Commerce transactions, it has SALE and RETURN endpoints (and some other ...
6
votes
4answers
1k views

From a high level programming perspective, where does the 'different-paradigm' barrier between C# and F# really kick in?

I'm aware that they both use different programming paradigms, but from a high level perspective apart from differing syntax it seems most basic tasks can be achieved in similar fashion. I only say ...
5
votes
4answers
2k views

Do large test methods indicate a code smell?

I have a particular method called TranslateValues() (Cyclomatic-Complexity of 5) which I would like to test. The test requires a substantial number of mock objects which take up most of the method; ...
4
votes
4answers
304 views

How to enforce how an interface is consumed

Imagine I have an interface: public interface MyInterface { void CallMeFirst(); void CallMeDuringApplicationLifecycle(); void CallMeOnApplicationExit(); } What is the best way of ...
4
votes
4answers
6k views

invoking methods within a conditional expression

In an oft-cited (if dated) reference for C# coding standards (pdf; from Lance Hunt), the statement is made, 33. Avoid invoking methods within a conditional expression. I've not seen this ...
4
votes
5answers
6k views

Pattern for select case on object type (of interface)

I have read that doing a select case is often a code smell. There are cases however where an interface cannot solve my problem. For instance, I have a set of date filter objects (last 7 days, last ...
3
votes
2answers
319 views

Implementing set of processes in a stored procedure or through the code?

I want to know what's the suitable method to implement the following case (best practice). If i make a set of processes like this: select data from set of DB tables. loop on the selected result. ...
3
votes
3answers
432 views

How to decide, should I put methods to abstract class or to interface?

I'm writing an app it needs to have generic registration step item. It needs to be able to do some specific things (I use interface for that) and it needs to be a visual element (of Xamarin. It doesn'...
3
votes
4answers
674 views

What is the benefit of encapsulating a collection inside a class?

Please see the code below: public class Customer { private readonly IList<Order> _orders = new List<Order>(); public string FirstName { get; set; } ...
3
votes
2answers
3k views

What do you suggest for cross platform apps, including web

I have always preferred cross platform development over most other concepts as long as I can remember. Which is one of the reason I never got into .Net. Currently, I use php/javascript/python as my ...
2
votes
2answers
371 views

Moving legacy application to a testable framework?

We have a web application which contains a web service with over 50 methods. The application is currently installed at a number of sites and is currently being maintained by one developer. The ...
1
vote
3answers
3k views

Why not make everything private or public? [closed]

In code there are private and public declarations. Why shouldn't I make everything private or make everything public?
1
vote
2answers
586 views

Should I mock a Domain Service?

I am trying to decide whether to introduce mocks in my isolated Domain Model tests. I have a class method similar to this: public Offer AssignOffer(OfferType offerType, IOfferValueCalculator ...
1
vote
3answers
2k views

Domain Driven Design in an Onion Architecture

I recently asked this question: Should the domain layer be dependent on NHibernate? I have read a lot of questions today, where answerers state that the Domain Layer should only contain Business ...
1
vote
1answer
206 views

Have I understood the term Honeycomb correctly?

Following on from my previous question and the comments under the accepted answer: One Acceptance Test project per layer or one Acceptance Test project per Bounded Context I have done a lot of ...
1
vote
4answers
4k views

Force Derived Class to Implement Static Method C#

So the situation is like, I have few classes, all of which have a standard CRUD methods but static. I want to create a base class which will be inherited so that it can force to implement this CRUD ...
0
votes
2answers
2k views

A sample Memento pattern: Is it correct?

Following this query on memento pattern, I have tried to put my understanding to test. Memento pattern stands for three things: Saving state of the "memento" object for its successful ...
-1
votes
1answer
691 views

Designing XML - confused between attributes and elements [closed]

I have to design an xml structure to set standard data exchange with my client. We deal with payments and its related data. At now, my XML data looks like this: <PAYMENTS> <CURRENCY>...
89
votes
16answers
18k views

Do the young minds need to learn the pointer concepts?

Why did the C master Dennis Ritchie introduce pointers in C? And why did the other programming languages like VB.NET or Java or C# eliminate them? I have found some points in Google, and I want to ...
66
votes
12answers
13k views

Does a constructor that validates its arguments violate SRP?

I am trying to adhere to the Single Responsibility Principle (SRP) as much as possible and got used to a certain pattern (for the SRP on methods) heavily relying on delegates. I'd like to know if this ...
104
votes
5answers
11k views

Aren't the guidelines of async/await usage in C# contradicting the concepts of good architecture and abstraction layering?

This question concerns the C# language, but I expect it to cover other languages such as Java or TypeScript. Microsoft recommends best practices on using asynchronous calls in .NET. Among these ...
9
votes
10answers
13k views

Switch from C# to Java, which “gotchas” I should care?

I may have to switch to Java for new project. I have very little knowledge about Java, because I've mainly studied and used C#, and I'm afraid of the differences between these two language/platform ...
64
votes
11answers
19k views

How can I convince my boss that ANSI C is inadequate for our new project? [closed]

A few months ago, we started developing an app to control an in-house developed test equipment and record a set of measurements. It should have a simple UI, and would likely require threads due to the ...
53
votes
2answers
15k views

Why is 'void' not allowed as a generic type in C#

What were the design decisions that argued in favour of void not being constructable and not being allowed as a generic type? After all it is just a special empty struct and would have avoided the ...
18
votes
13answers
42k views

What are the practical uses of Windows Services? [closed]

I am new to working with Windows Services. Although I have learnt to create Windows Services in VS2010 I would like to know some practical ways in which windows services could be used? I tried ...
32
votes
10answers
15k views

Why the question “give five things you hate about C#” is so difficult to answer during an interview? [closed]

In podcast 73, Joel Spolsky and Jeff Atwood discuss, among other subjects, "five things everyone should hate about their favorite programming language": If you’re happy with your current tool chain,...
25
votes
7answers
18k views

Why would I ever use delegates if I'm not doing events? [duplicate]

I am trying to learn how to do events in C#, and according to the MSDN Events tutorial, Events are declared using delegates. If you have not yet studied the Delegates Tutorial, you should do so ...
14
votes
3answers
10k views

How do I set up MVP for a Winforms solution?

I have used MVP and MVC in the past, and I prefer MVP as it controls the flow of execution so much better in my opinion. I have created my infrastructure (datastore/repository classes) and use them ...
67
votes
10answers
20k views

What is a proper use of downcasting?

Downcasting means casting from a base class (or interface) to a subclass or leaf class. An example of a downcast might be if you cast from System.Object to some other type. Downcasting is unpopular, ...
49
votes
11answers
4k views

I don't understand how TDD helps me get a good design if I need a design to start testing it

I'm trying to wrap my head around TDD, specifically the development part. I've looked at some books, but the ones I found mainly tackle the testing part - the History of NUnit, why testing is good, ...
37
votes
6answers
10k views

Good example of complex code using TDD [closed]

What would be a good example of the use of TDD in large, real-life, complex, projects? All the examples I've seen so far are toy projects for the purpose of a book or a paper... Can you name an ...
57
votes
9answers
8k views

Readability versus maintainability, special case of writing nested function calls

My coding style for nested function calls is the following: var result_h1 = H1(b1); var result_h2 = H2(b2); var result_g1 = G1(result_h1, result_h2); var result_g2 = G2(c1); var a = F(result_g1, ...
32
votes
8answers
3k views

S.O.L.I.D., avoiding anemic domains, dependency injection?

Although this could be a programming language agnostic question, I'm interested in answers targeting the .NET ecosystem. This is the scenario: suppose we need to develop a simple console application ...
28
votes
5answers
7k views

Why can't Java/C# implement RAII?

Question: Why can't Java/C# implement RAII? Clarification: I am aware the garbage collector is not deterministic. So with the current language features it is not possible for an object's Dispose() ...
14
votes
2answers
15k views

Is this a good Visual Studio solution structure for a domain driven design RESTful web service?

I am building a .NET 4.5 C# Web API RESTful solution and I would like someone to tell me if my project solution is correct and/or wise(-enough?) for a solution designed using Domain Driven Design, ...
49
votes
11answers
26k views

Why are /// comment blocks important?

Someone once said we should prefix all our methods with the /// <summary> comment blocks (C#) but did not explain why. I started to use them and found they annoyed me quite a bit, so stopped ...
20
votes
3answers
39k views

Best design for Windows forms that will share common functionality

In the past, I have used inheritance to allow the extension of Windows forms in my application. If all of my forms would have common controls, artwork, and functionality, I would create a base form ...
21
votes
9answers
3k views

How to teach Exception Handling for New Programmers? [closed]

How do you go about teaching Exception Handling to Programmers. All other things are taught easily - Data Structures, ASP.NET, WinForms, WPF, WCF - you name it, everything can be taught easily. With ...
65
votes
3answers
27k views

Should we include Nuget PACKAGE folder in version control?

I would like to know In C# or VB.NET project should we include the PACKAGE folder (nugget package folder that is created to the root of my project that contain the nupkg files and other content) to ...
26
votes
2answers
4k views

Implementation of pure abstract classes and interfaces

Although this isn't mandatory in the C++ standard, it seems the way GCC for example, implements parent classes, including pure abstract ones, is by including a pointer to the v-table for that abstract ...