Sunday, March 22, 2009

C# 4.0 Interview questions



What are the key new features in C# 4.0

The new features in C# 4.0 fall into four groups:
Dynamic lookup
Dynamic lookup allows you to write method, operator and indexer calls, property and field accesses, and even object invocations which bypass the C# static type checking and instead gets resolved at runtime.
Named and optional parameters
Parameters in C# can now be specified as optional by providing a default value for them in a member declaration. When the member is invoked, optional arguments can be omitted. Furthermore, any argument can be passed by parameter name instead of position.
COM specific interop features
Dynamic lookup as well as named and optional parameters both help making programming against COM less painful than today. On top of that, however, we are adding a number of other small features that further improve the interop experience.

What is Named and optional argumnent.

C# 4.0 does not permit you to omit arguments between commas as in M(1,,3). This could lead to highly unreadable comma-counting code. Instead any argument can be passed by name. Thus if you want to omit only y from a call of M you can write:
M(1, z: 3); // passing z by name
or
M(x: 1, z: 3); // passing both x and z by name
or even
M(z: 3, x: 1); // reversing the order of arguments
All forms are equivalent, except that arguments are always evaluated in the order they appear, so in the last example the 3 is evaluated before the 1.
Optional and named arguments can be used not only with methods but also with indexers and constructors.

Other ASP.Net related interview questions are available at

Set 1 of ASP.Net Interview questions or Asp.Net FAQs
Set 2 of ASP.Net Interview questions or Asp.Net FAQs

Set 3 of ASP.Net Interview questions or ASP.Net FAQs

Basic .Net questions are available at .Net Frame works FAQ or .Net interview question

No comments: