C# 4.0 introduced features like dynamic objects, COM interoperability improvements, and optional and named parameters. Use this tag if your question specifically pertains to C# 4.0 specific features. The C# tag should be used if your question is not specific to C# 4.0 features.

learn more… | top users | synonyms (1)

522
votes
5answers
46k views

What are the correct version numbers for C#?

What are the correct version numbers for C#? What came out when? Why can't I find any answers about C# 3.5? [This question is primarily to aid those who are searching for an answer using an incorrect ...
181
votes
7answers
20k views

What are the true benefits of ExpandoObject?

The ExpandoObject class being added to .NET 4 allows you to arbitrarily set properties onto an object at runtime. Are there any advantages to this over using a Dictionary<string,object>, or ...
157
votes
6answers
65k views

Interop type cannot be embedded

I am creating an web application on the .net 4.0 framework (beta2 ) in C#. When I try to use a assembly called "ActiveHomeScriptLib", I get the following error: Interop type ...
124
votes
4answers
11k views

Why are C# 4 optional parameters defined on interface not enforced on implementing class?

I noticed that with the optional parameters in C# 4 if you specify a parameter as optional on an interface you DON'T have to make that parameter optional on any implementing class: public interface ...
97
votes
4answers
8k views

How does the C# compiler detect COM types?

EDIT: I've written the results up as a blog post. The C# compiler treats COM types somewhat magically. For instance, this statement looks normal... Word.Application app = new Word.Application(); ...
85
votes
3answers
2k views

Why does this (null || !TryParse) conditional result in “use of unassigned local variable”?

The following code results in use of unassigned local variable "numberOfGroups": int numberOfGroups; if(options.NumberOfGroups == null || !int.TryParse(options.NumberOfGroups, out numberOfGroups)) { ...
71
votes
3answers
18k views

What is Microsoft.csharp.dll in .NET 4.0

This DLL is added by default in Visual Studio 2010 projects. What is this new assembly used for? It does not seem to contain much after looking at it using Reflector and Google does not seem to have ...
69
votes
2answers
19k views

Parallel.ForEach vs Task.Factory.StartNew

What is the difference between the below code snippets? Won't both be using threadpool threads? For instance if I want to call a function for each item in a collection, ...
68
votes
8answers
6k views

To Workflow or Not to Workflow?

I am responsible for a team of developers who will are about to start development of a light weight insurance claims system. The system involves a lot of manual tasks and business workflows and we are ...
64
votes
10answers
4k views

How does a static constructor work?

namespace MyNameSpace { static class MyClass { static MyClass() { //Authentication process.. User needs to enter password } public static void ...
63
votes
4answers
22k views

How is Generic Covariance & Contra-variance Implemented in C# 4.0?

I didn't attend PDC 2008, but I heard some news that C# 4.0 is announced to support Generic covariance and contra-variance. That is, List<string> can be assigned to List<object>. How could ...
62
votes
5answers
2k views

Why covariance and contravariance do not support value type

IEnumerable<T> is co-variant but it does not support value type, just only reference type. The below simple code is compiled successfully: IEnumerable<string> strList = new ...
60
votes
3answers
8k views

Why does 0.ToString(“#.##”) return an empty string instead of 0.00 or at least 0?

Why does 0.ToString("#.##") return an empty string? Shouldn't it be 0.00 or at least 0?
51
votes
3answers
2k views

Named arguments and generic type inference in C# 4.0

I had been programming under the assumption that, when calling a method in C# 4.0, supplying names for your arguments would not affect the outcome unless in doing so you were "skipping" one or more ...
50
votes
3answers
20k views

What is the difference between task and thread?

In C# 4.0, we have Task in the System.Threading.Tasks namespace. What is the true difference between Thread and Task. I did some sample program(help taken from MSDN) for my own sake of learning with ...

1 2 3 4 5 996
15 30 50 per page