New CSharp Language features 3.0 and 4.0: Difference between revisions
Jump to navigation
Jump to search
m (moved New C to New CSharp Language features 3.0 and 4.0) |
No edit summary |
||
Line 4: | Line 4: | ||
* see http://soumya.wordpress.com/2009/06/12/new-features-in-c-part-ii-c-3-0/ | * see http://soumya.wordpress.com/2009/06/12/new-features-in-c-part-ii-c-3-0/ | ||
* Automatic Properties | ==== Implicitly Typed Local Variables (aka 'Local Variable Type Inference') ==== | ||
* At first glance this feature looks like it does what the 'dreaded' VARIANT Type of Visual Basic 6 does, where it results in ''late-bound Type Inference'' which can cause very difficult-to-spot errors at runtime. | |||
* ''However'', Implicitly Typed Local Variables result in ''early-bound strongly-typed'' code, which is way better as its VB 6 'colleague' as it can not cause those errors at run-time! | |||
* Only works for ''local variables in a method'' (that is, not for Class Fields or Method Arguments). | |||
* Usage | |||
* Extension Methods | ** Use new <code>var</code> keyword for the declaration of such variables. | ||
** ''Should not be over-used'' as the source code is less explicit then when the Type it holds is stated explicitly. | |||
** Can be a time saver for declaration of long types, esp. Generic ones; there it fine to be used and actually can result in easier-to-read code. | |||
* '''Details: [http://www.danielmoth.com/Blog/local-variable-type-inference-in-c-30.aspx]''' | |||
* | |||
==== Anonymous Types ==== | |||
==== Auto-implemented Properties (aka 'Automatic Properties') ==== | |||
* used already in the web server for conference backend. saves writing dumb code | |||
==== Object Initializers ==== | |||
* used by ext.net which is used by the web server for conference backend. | |||
==== Collection Initializers, Dictionary Initializers ==== | |||
==== Partial Methods ==== | |||
* Available in Partial Classes only. | |||
==== Extension Methods ==== | |||
==== Lambda Expressions ==== | |||
* Replace Anonymous Methods, which were new in C# 2.0. | |||
==== LINQ ==== | |||
=== C# 4.0 === | === C# 4.0 === | ||
Line 19: | Line 41: | ||
* see http://soumya.wordpress.com/2009/06/12/new-features-in-c-part-iii-c-4-0/ | * see http://soumya.wordpress.com/2009/06/12/new-features-in-c-part-iii-c-4-0/ | ||
==== Named Parameters ==== | |||
* | * This looks most interesting for us. | ||
* Dynamic Support | |||
* | ==== Optional Parameters ==== | ||
* COM | * This looks very interesting for us, too. | ||
==== Dynamic Support ==== | |||
==== Variance ==== | |||
==== COM Interop ==== | |||
* Probably not interesting for us as the OpenPetra Client should stay platform-independent (COM is available only on Windows OS's). | |||
* Could ''potentially'' be useful for optional plug-ins for the OpenPetra Client that would need COM to fulfill their roles, though. Obviously those plug-ins would work on only Windows OS's then. | |||
== Mono and new C# features == | == Mono and new C# features == | ||
TODO | TODO |
Revision as of 14:16, 26 October 2011
New features
C# 3.0
- see http://www.codeproject.com/KB/cs/csharp3.aspx
- see http://soumya.wordpress.com/2009/06/12/new-features-in-c-part-ii-c-3-0/
Implicitly Typed Local Variables (aka 'Local Variable Type Inference')
- At first glance this feature looks like it does what the 'dreaded' VARIANT Type of Visual Basic 6 does, where it results in late-bound Type Inference which can cause very difficult-to-spot errors at runtime.
- However, Implicitly Typed Local Variables result in early-bound strongly-typed code, which is way better as its VB 6 'colleague' as it can not cause those errors at run-time!
- Only works for local variables in a method (that is, not for Class Fields or Method Arguments).
- Usage
- Use new
var
keyword for the declaration of such variables. - Should not be over-used as the source code is less explicit then when the Type it holds is stated explicitly.
- Can be a time saver for declaration of long types, esp. Generic ones; there it fine to be used and actually can result in easier-to-read code.
- Use new
- Details: [1]
Anonymous Types
Auto-implemented Properties (aka 'Automatic Properties')
- used already in the web server for conference backend. saves writing dumb code
Object Initializers
- used by ext.net which is used by the web server for conference backend.
Collection Initializers, Dictionary Initializers
Partial Methods
- Available in Partial Classes only.
Extension Methods
Lambda Expressions
- Replace Anonymous Methods, which were new in C# 2.0.
LINQ
C# 4.0
- see http://www.codeproject.com/KB/cs/CSharp4Features.aspx
- see http://soumya.wordpress.com/2009/06/12/new-features-in-c-part-iii-c-4-0/
Named Parameters
- This looks most interesting for us.
Optional Parameters
- This looks very interesting for us, too.
Dynamic Support
Variance
COM Interop
- Probably not interesting for us as the OpenPetra Client should stay platform-independent (COM is available only on Windows OS's).
- Could potentially be useful for optional plug-ins for the OpenPetra Client that would need COM to fulfill their roles, though. Obviously those plug-ins would work on only Windows OS's then.
Mono and new C# features
TODO