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

19
votes
3answers
15k views

What is constructor injection?

I have been looking at the terms constructor injection and dependency injection while going through articles on (Service locator) design patterns. When I googled about constructor injection, I got ...
19
votes
5answers
1k views

Why isn't java used as a build language?

If Java is a general purpose language, and building a program is something that can be described using the Java language, why isn't this the best way to write build files and instead we use tools like ...
19
votes
2answers
14k views

Separating data access in ASP.NET MVC

I want to make sure I'm following industry standards and best practices with my first real crack at MVC. In this case, it's ASP.NET MVC, using C#. I will be using Entity Framework 4.1 for my model, ...
19
votes
7answers
3k views

When should I use a 2-property class over a pre-built structure like a KeyValuePair?

When should you put Key/Value type of data in it's own class instead of using a pre-built generic structure, such as a KeyValuePair or a Tuple? For example, most ComboBoxes I create contain a ...
19
votes
3answers
2k views

Difficulties With TDD & Refactoring (Or - Why Is This More Painful Than It Should Be?)

I wanted to teach myself to use the TDD approach and I had a project I had been wanting to work on for a while. It wasn't a large project so I thought it would be a good candidate for TDD. However, I ...
19
votes
5answers
14k views

Is There a Real Advantage to Generic Repository?

Was reading through some articles on the advantages of creating Generic Repositories for a new app (example). The idea seems nice because it lets me use the same repository to do several things for ...
19
votes
3answers
4k views

Is c# actually a multiplatform language?

C# (and the .net platform in general) is looking like it's becoming a good option form multi-targeting apps : official MS .net framework : full blow windows development, asp.net dev, Windows phone ...
19
votes
6answers
64k views

How should data be passed between client-side Javascript and C# code behind an ASP.NET app?

I'm looking for the most efficient / standard way of passing data between client-side Javascript code and C# code behind an ASP.NET application. I've been using the following methods to achieve this ...
19
votes
1answer
3k views

Async network programming using Reactive Extensions

After doing some (more-or-less) "low-level" async socket programming years ago (in an Event-based Asynchronous Pattern (EAP) fashion) and recently moving "up" to a TcpListener (Asynchronous ...
18
votes
25answers
15k views

How many lines of code can a C# developer produce per month? [closed]

An executive at my workplace asked me and my group of developers the question: How many lines of code can a C# developer produce per month? An old system was to be ported to C# and he would ...
18
votes
13answers
1k views

C# or .Net features to cut off assuming no backward compatibility needed? [closed]

Any product or framework evolves. Mainly it's done to catch up the needs of it's users, leverage new computing powers and simply make it better. Sometimes the primary design goal also changes with the ...
18
votes
4answers
5k views

If MVC is “Separation of Concerns” then why was Razor Syntax introduced?

My question is related to MVC design pattern and Razor Syntax introduced by Microsoft. While learning MVC design pattern I was told that the idea is based upon a principle known as Separation of ...
18
votes
5answers
2k views

Create new object or reset every property?

public class MyClass { public object Prop1 { get; set; } public object Prop2 { get; set; } public object Prop3 { get; set; } } Suppose I have an object myObject of ...
18
votes
10answers
4k views

Declaring interface in the same file as the base class, is it a good practice?

To be interchangable and testable, normally services with logic needs to have interface, e.g. public class FooService: IFooService { ... } Design-wise, I agree with this, but one of the things ...
18
votes
4answers
13k views

Any real use of pointers in C#? [closed]

What is a situation while coding in C# where using pointers is a good or necessary option? I'm talking about unsafe pointers.
18
votes
9answers
2k 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 ...
18
votes
5answers
3k views

What naming convention for C# file that contains multiple classes?

In C# projects, we frequently group small and tightly related classes into the same .cs file. This practice reduces the friction of dealing with a myriad of files containing close to no actual code. ...
18
votes
3answers
2k views

Why isn't the Stab language more widely used? [closed]

I am wondering if there are technical reasons that make Stab an unsuitable alternative to Java. Stab borrows heavily from C#, bringing many C# features to the JVM: Less verbosity type inference ...
18
votes
1answer
1k views

Confusion between F# and C# [duplicate]

I am fairly new to functional programming and C#/F#. What is unclear to me is: Can you do functional programming in C# and/or in F#? Or is it something like, you write some OO code in C#, and some FP ...
18
votes
2answers
622 views

Why does shared state degrade performance?

I've been working under the share-nothing principle of concurrent programming. Essentially, all my worker threads have immutable read-only copies of the same state which is never shared between them ...
17
votes
7answers
3k views

Why is instance creation the way it is?

I've learned C# over the course of the past six months or so and am now delving into Java. My question is about instance creation (in either language, really) and it's more of: I wonder why they did ...
17
votes
7answers
6k views

How does throwing an ArgumentNullException help?

Let's say I have a method: public void DoSomething(ISomeInterface someObject) { if(someObject == null) throw new ArgumentNullException("someObject"); someObject.DoThisOrThat(); } I've been ...
17
votes
7answers
2k views

What can one do to improve readability of math-oriented code in C#, Java, and similar? [closed]

As both a C programmer and a C# programmer, one of the things I don't like about C# is how verbose math functions are. Every time you would have to use a Sin, cosine, or power function for example, ...
17
votes
7answers
4k views

Team member questioning moving from VBA to C#

Background Last year, I was asked to create a tool to be used for business planning for around 10 users. This was done on behalf of another IT team who "sub-contracted" the work to me, and due to the ...
17
votes
11answers
10k views

Which Continuous Integration framework do you use and why? [closed]

There are quite a few different Continuous Integration (CI) frameworks out there and I'm wondering which is the most popular. Which frameworks have you used at firms where you work? Is there any ...
17
votes
14answers
3k views

Is there ever a reason to use an array when lists are available? [closed]

It seems like List<T> in C# can do everything an array can do and more, and seems also just as efficient in memory and performance as an array. So why would I ever want to use an array? I'm ...
17
votes
5answers
7k views

When and why you should use void (instead of i.e. bool/int)

I occasionally run into methods where a developer chose to return something which isn't critical to the function. I mean, when looking at the code, it apparently works just as nice as a void and after ...
17
votes
9answers
627 views

Should if statments be in inner or outer method?

Which of these designs is better? What are the pros and cons of each? Which one would you use? Any other suggestions of how to deal with methods like is are appreciated. It is reasonable to assume ...
17
votes
9answers
5k views

Why hasn't C# gained much traction within the opensource community? [closed]

I'm not expecting C# to be on par with say Java or Python in the open source community, but it still surprises me just how far behind it is. 'Multi language' open source repos like google code or ...
17
votes
10answers
2k views

Best Practices and Etiquette for Setting up Email Notifications

If you were going to set up a Email Alerts for the customers of your website to subscribe to, what rules of etiquette ought to be followed? I can think of a few off the top of my head: Users can ...
17
votes
5answers
17k views

Multiple classes in a single .cs file - good or bad?

Is it advisable to create multiple classes within a .cs file or should each .cs file have an individual class? For example: public class Items { public class Animal { } public class ...
17
votes
9answers
5k views

Whether to put the business logic in Stored Procedure or Not?

There is always a debate over the topic - "Whether to put the business logic in Stored Procedure or Not?". If we decide not to use the ORM Tool and not to put the Business Logic in Stored Procedure ...
17
votes
6answers
20k views

Advantages and disadvantages to using XAML/C# or HTML5/JavaScipt for Metro apps? [closed]

I was just wondering if there are any major advantages or disadvantages to using either XAML/C# or HTML5/JavaScript for Metro Apps.
17
votes
7answers
1k views

Why should one want to disable compiler warnings?

This answer and the comments added to it show a way to disable several compiler warnings using #pragma directives. Why would one want to do that? Usually the warnings are there for a reason, and I've ...
17
votes
3answers
20k 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 ...
17
votes
1answer
749 views

Is C#-4.0 an open standard?

The Ecma-334 (ISO/IEC 23270:2006) standard corresponds to the version 2.0 of the language. Specification of version 4.0 is freely available from Microsoft, but Microsoft's open specifications list ...
16
votes
9answers
3k views

Will Java catch up with C#? [closed]

Today I posted a question asking about which language C# or Java would be better for me to study. I had some great answers. One thing that came up was that perhaps Java is now rather behind C# with ...
16
votes
8answers
14k views

Senior Interview LINQ questions [closed]

I'm preparing a LINQ section in interview questions for senior programmers. What are the most interesting questions in LINQ to include? And why?
16
votes
5answers
2k views

Use of keyword “Using” in C# interface

When I'm using C# to write some code and I define an interface using Visual Studio 2010, it always includes a number of "using" statements (as shown in the example) using System; using ...
16
votes
7answers
2k views

What is the correct order to read these books? [closed]

I'm a junior C# developer, I learned at home and now I got my first job :) I want to buy these books. But what is the correct order to read these books? Code Complete: A Practical Handbook of ...
16
votes
5answers
2k views

How would you teach C# delegate to a newbie? [closed]

I was reviewing Andrew Troelsen book on C# 4.0. The part that explains delegates starts as smooth as: public class SimpleMath { //declare delegate public delegate int BinaryOp(int x, int y); ...
16
votes
6answers
3k views

What is the philosophy/reasoning behind C#'s Pascal-casing method names?

I'm just starting to learn C#. Coming from a background in Java, C++ and Objective-C, I find C#'s Pascal-casing its method-names rather unique, and a tad difficult to get used to at first. What is the ...
16
votes
4answers
2k views

Is there a canonical source for learning C# and .NET internals? [closed]

I have been a C++ programmer for last several years with a bit of C# here and there. In my latest job, I work heavily on C#. I picked most of my C# by following the code-base or random google searches ...
16
votes
3answers
940 views

Detecting IEnumerable “State Machines”

I just read an interesting article called Getting too cute with c# yield return It made me wonder what the best way is to detect whether an IEnumerable is an actual enumerable collection, or if it's ...
16
votes
4answers
3k views

Is the “Gets or sets ..” necessary in XML documentation of properties?

I am looking for a recommendation of a best practice for XML comments in C#. When you create a property, it seems like that the expected XML documentation has the following form: /// <summary> ...
16
votes
6answers
2k views

How to hire a good C# developer if I don't know C#? [closed]

I'm a C++ developer. I know how Windows works on the native level, but I'm not a big expert in C# and .NET. Now I need a C# developer in my team (all my developers are C++). How can I hire a great C# ...
16
votes
11answers
4k views

How does one meaningfully measure maintainability?

Context: I'm an enterprise developer in an all-MS shop. Can anyone recommend a good way of objectively measuring maintainability of a piece of code or an application? Why maintainability: I'm tired ...
16
votes
4answers
5k views

Is a Unique ID column needed in a many-to-many (junction) table?

Getting a few projects started with EF, but I had some questions about join tables and keys etc. Lets say I have a table of applications and a table of permissions. Applications have many permissions ...
16
votes
3answers
1k views

Brittle unit tests due to need for excessive mocking

I've been struggling with an increasingly annoying problem regarding our unit tests that we are implementing in my team. We are attempting to add unit tests into legacy code that wasn't well designed ...
16
votes
6answers
3k views

Why is closure important for JavaScript?

C#'s lambda expression also has closures but is rarely discussed by the C# communities or books. I see far more JavaScript people and books talk about its closures than they do in the C# world. Why is ...