Welcome

Monday, 5 October 2015

Statically typed – This means the type of variable declared is decided by the compiler at compile time.

Dynamically typed - This means the type of variable declared is decided by the compiler at runtime time.

Need to initialize at the time of declaration.
e.g., var str=”I am a string”;
Looking at the value assigned to the variable str, the compiler will treat the variable stras string.

Noneed to initialize at the time of declaration.
e.g., dynamic str;str=”I am a string”; //Works fine and compilesstr=2; //Works fine and compiles

Errors are caught at compile time.
Since the compiler knows about the type and the methods and properties of the type at the compile time itself

Errors are caught at runtime
Since the compiler comes to about the type and the methods and properties of the type at the run time.

Visual Studio shows intellisense since the type of variable assigned is known to compiler.

Intellisense is not available since the type and its related methods and properties can be known at run time only

e.g., var obj1;
will throw a compile error since the variable is not initialized. The compiler needs that this variable should be initialized so that it can infer a type from the value.

e.g., dynamic obj1;will compile;

e.g. var obj1=1;
will compilevar obj1=” I am a string”;will throw error since the compiler has already decided that the type of obj1 is System.Int32 when the value 1 was assigned to it. Now assigning a string value to it violates the type safety.

e.g. dynamic obj1=1;
will compile and rundynamic obj1=” I am a string”;will compile and run since the compiler creates the type for obj1 as System.Int32 and then recreates the type as string when the value “I am a string” was assigned to it.
This code will work fine.

Thursday, 15 May 2014

Each style has their pros and cons. Query syntax is nicer when it comes to joins and it has the useful letkeyword that makes creating temporary variables inside a query easy.

Fluent syntax on the other hand has a lot more methods and operations that aren't exposed through the query syntax. Also since they are just extension methods you can write your own.

I have found that every time I start writing a LINQ statement using the query syntax I end up having to put it in parenthesis and fall back to using fluent LINQ extension methods. Query syntax just doesn't have enough features to use by itself.

There are some LINQ extension methods which do not have counterparts in LINQ query expressions, and will require the use of Lambda Expressions. A good example is Enumerable.ToLookup - if you want to create an ILookup, you need to use lambdas to generate this