SAIFUR RAHMAN – A SENIOR SOFTWARE ENGINEER AT SOLENTIVE OUTLINES HIS OPINION ON C# 4.0.
If C# 3.0 was all about Language Integrated Query (LINQ), then C# 4.0 is all about dynamic programming.
What exactly does that mean?
It means that C# 4.0 brings flexibility and declarative style of programming to C#.
Key enhancements include:
Named Arguments, Optional Arguments and Default Values When enforced as a standard in coding guidelines, named arguments can make a program more readable. Reading a name (a meaningful name of course) along with the value in a function call will make it easier to understand what argument was expected and what is it that we are passing.
Concurrent GC (Garbage Collector) is being replaced by Background GC in C# 4.0 Concurrent GC is the mode of the GC that we use in desktop applications for example. The goal of the concurrent GC is to minimise pause time, and it does so by allowing us to still allocate while a GC is in progress (hence the concurrent part).
Concurrent GC is only available in workstation mode.
In server mode for example (which is what we use in ASP.NET when we have multiple processors/cores), all simplified managed calls are paused while in a GC, which means that we can’t allocate anything. The process pauses slightly while in a GC but on the other hand what we lose in pause time, we gain in throughput as GCs are made by x number of GC threads concurrently, where x is #procs*#cores.
In concurrent GC we were allowed to allocate while in a GC, but we are not allowed to start another GC while in a GC. This in turn means that the maximum we are allowed to allocate while in a GC is whatever space we have left on one segment (currently 16 MB in workstation mode) minus anything that is already allocated there.
The difference in Background mode is that we are allowed to start a new GC (gen 0+1) while in a full background GC, and this allows us to even create a new segment to allocate in, if necessary. In short, the blocking that could occur before, when we allocated all we could in one segment, won’t happen anymore.
LINQ to SQL changes Improvements in .NET 4.0
LinqDataSource now supports inherited entities
LinqDataSource support for ASP.NET query extenders added
SubmitChanges no longer silently consumes transaction rollback exceptions
SubmitChanges deals with timestamps in a change conflict scenario properly
Opening a DBML file no longer causes it to be checked out of source control
Read what others have said about this topic: https://geekswithblogs.net/sdorman/archive/2008/11/16/c-4.0-dynamic-programming.aspx https://blogs.msdn.com/samng/archive/2008/10/29/dynamic-in-c.aspx https://blogs.msdn.com/kirillosenkov/archive/2009/05/01/a-simple-sample-for-c-4-0-dynamic-feature.aspx https://blogs.msdn.com/cburrows/archive/2008/10/28/c-dynamic-part-ii.aspx https://blogs.msdn.com/cburrows/archive/2008/10/29/c-dynamic-part-iii.aspx https://www.codethinked.com/post/2008/10/29/C-40-New-Features-Part-2-default-and-named-parameters.aspx https://davidhayden.com/blog/dave/archive/2009/06/02/CSharp4OptionalNamedParameters.aspx https://blogs.msdn.com/maoni/archive/2008/11/19/so-what-s-new-in-the-clr-4-0-gc.aspx