.NET 4.0 Framework Interview Questions and Answers

3/15/2011 No Comment
Microsoft.NET 4.0 Framework Interview Questions and Answers,Net framework 4.0 Interview Questions,.Net Framework 4.0 – A Parallel – Programming Initiative,.NET Framework Interview questions

Where do I get .Net 4.0 from?

You can download .NET 4.0 beta from http://www.microsoft.com/downloads/details.aspx?FamilyID=ee2118cc-51cd-46ad-ab17-af6fff7538c9&displaylang=en 

What are the important new features in .NET 4.0?

Rather than walking through the 100 new features list, let's concentrate on the top 3 features which we think are important.
. Windows work flow and WCF 4.0:- This is a major change in 4.0. In WCF they have introduced simplified configuration, discovery, routing service, REST improvements and workflow services. In WWF they have made changes to the core programming model of workflow. Programming model has been made more simple and robust. The biggest thing is the integration between WCF and WWF.

. Dynamic Language runtime: - DLR adds dynamic programming capability to .NET 4.0 CLR. We will talk more about it as this FAQ moves ahead.

. Parallel extensions: - This will help to support parallel computing for multi-core systems. .NET 4.0 has PLINQ in the LINQ engine to support parallel execution. TPL (Task parallel library) is introduced which exposes parallel constructs like parallel 'For' and 'ForEach' loops, using regular method calls and delegates. We will be talking in more details of the above features in the coming sections.

What's the most important new feature of .NET 4.0?

WCF and WWF new features are one of the most interesting features of all. Especially the new programming model of WWF and its integration with WCF will be an interesting thing to watch.
DLR, parallel programming and other new features somehow just seem to be brownie points rather than compelling features.

What is DLR in .NET 4.0 framework?

DLR (Dynamic language runtime) is set of services which add dynamic programming capability to CLR. DLR makes dynamic languages like LISP, Javascript, PHP,Ruby to run on .NET framework.


There are two types of languages statically typed languages and dynamically typed languages. In statically typed languages you need to specify the object during design time / compile time. Dynamically typed languages can identify the object during runtime. .NET . DLR helps you to host code written in dynamic languages on top of your CLR.

Due to DLR runtime, dynamic languages like ruby, python, JavaScript etc can integrate and run seamlessly with CLR. DLR thus helps to build the best experience for your favorite dynamic language. Your code becomes much cleaner and seamless while integrating with the dynamic languages.

Integration with DLR is not limited to dynamic languages. You can also call MS office components in a much cleaner way by using COM interop binder.
One of the important advantages of DLR is that it provides one central and unified subsystem for dynamic language integration.

Can you give more details about DLR subsystem?

DLR has 3 basic subsystems:-
. Expression trees: - By this we can express language semantics in form of AST (Abstract syntax tree). DLR dynamically generates code using the AST which can be executed by the CLR runtime. An expression tree is a main player which helps to run various dynamic languages javascript, ruby with CLR. . Call site caching: - When you make method calls to dynamic objects DLR caches information about those method calls. For the other subsequent calls to the method DLR uses the cache history information for fast dispatch.
. Dynamic object interoperability (DOI):- DOI has set of classes which can be used to create dynamic objects. These classes can be used by developers to create classes which can be used in dynamic and static languages.
We will be covering all the above features in more detail in the coming FAQ sections.

How can we consume an object from dynamic language and expose a class to dynamic languages?

To consume a class created in DLR supported dynamic languages we can use the 'Dynamic' keyword. For exposing our classes to DLR aware languages we can use the 'Expando' class.
So when you want to consume a class constructed in Python , Ruby , Javascript , COM languages etc we need to use the dynamic object to reference the object. If you want your classes to be consumed by dynamic languages you need to create your class by inheriting the 'Expando' class. These classes can then be consumed by the dynamic languages. We will be seeing both these classes in the coming section.
Do not forget to download help document for library authors regarding how to enable the dynamic language across platform using DLR.

Can we see a sample of 'Dynamic' objects?

We had already discussed that 'Dynamic' objects helps to consume objects which are created in dynamic languages which support DLR.The dynamic keyword is a part of dynamic object interoperability subsystem.
If you assign an object to a dynamic type variable (dynamic x=new SomeClass()), all method calls, property invocations, and operator invocations on 'x' will be delayed till runtime, and the compiler won't perform any type checks for 'x' at compile time.
Consider the below code snippet where we are trying to do method calls to excel application using interop services.
// Get the running object of the excel application
object objApp = System.Runtime.InteropServices.Marshal.GetActiveObject
("Excel.Application");
// Invoke the member dynamically
object x = objApp.GetType().InvokeMember("Name", System.Reflection.
BindingFlags.GetProperty, 
null, objApp, null);
// Finally get the value by type casting
MessageBox.Show(x.ToString());
The same code we now write using 'dynamic' keyword.
// Get the object using 
dynamic objApp1 = System.Runtime.InteropServices.Marshal.
GetActiveObject("Excel.Application");
// Call the 
MessageBox.Show(objApp1.Name);
You can clearly notice the simplification of property invocation syntax. The 'invokemember' is pretty cryptic and prone to errors. Using 'dynamic' keyword we can see how the code is simplified.

If you try to view the properties in VS IDE you will see a message stating that you can only evaluate during runtime.

What's the difference between 'Dynamic', 'Object' and reflection?

Many developers think that 'Dynamic' objects where introduced to replace to 'Reflection' or the 'Object' data type. The main goal of 'Dynamic' object is to consume objects created in dynamic languages seamlessly in statically typed languages. But due to this feature some of its goals got overlapped with reflection and object data type.
Eventually it will replace reflection and object data types due to simplified code and caching advantages. The main goal of dynamic object was never introduced in the first place to replace 'reflection' or object data type, but due to overlapping features it did.
Dynamic
Object / Reflection
Dynamic object is a small feature provided in the DLR engine by which we can make calls to objects created in dynamic languages. The big picture is the DLR which helps to not only to consume, but also your classes can be exposed to dynamic languages.
Reflection and Object type is only meant for referencing types whose functions and methods are not know during runtime. Reflection and object type do not help to expose your classes to other languages. They are purely meant to consume objects whose methods are known until runtime.
Syntax code is quiet clean
Syntax has a bit of learning curve.
Performance is improved due to caching of method calls.
No caching of method calls exists currently.

What are the advantages and disadvantage of dynamic keyword?

We all still remember how we talked bad about VB6 (Well I loved the language) variant keyword and we all appreciated how .NET brought in the compile time check feature, well so why are we changing now.
Well, bad developers will write bad code with the best programming language and good developers will fly with the worst programming language. Dynamic keyword is a good tool to reduce complexity and it's a curse when not used properly.
So advantages of Dynamic keyword:-
. Helps you interop between dynamic languages.
. Eliminates bad reflection code and simplifies code complexity. . Improves performance with method call caching.
Disadvantages:-
. Will hit performance if used with strongly typed language.
Related Posts


No comments :

 

Aired | The content is copyrighted and may not be reproduced on other websites. | Copyright © 2009-2016 | All Rights Reserved 2016

Contact Us | About Us | Privacy Policy and Disclaimer