A Quick KT on dynamic vs. var keyword

The fundamental difference between 'var' and 'dynamic'
- 'var' keyword the type infer at compile time
- 'dynamic' keyword the type infer at run-time. 

'var' keyword is strongly implicitly typed variable and compiler knows type of variable from the initialization.

On mouse hover over the 'dynamic. keyword
 - Represents an object whose operations will be resolved at run-time

On mouse hover over the 'var' keyword
 - Infer type from value assigned to variable

It is not mandatory to assign value to dynamic type varibale but If you don’t initialize 'var' type at the time of declaration then compiler shouting an error
dynamic d_test; //ok
var v_t = "Test"; //ok
var v_k; //compile time error

Note I true believe too much use of dynamic could induce 
1. performance degredation 
2. Increase Runtime Errors possibilites which easyly can be redused at compilte time

XML Namespace Reminds OOPs Namespace

XML namespaces are used for providing uniquely named elements and attributes in an XML document. An XML instance may contain element or attribute names from more than one XML vocabulary. If each vocabulary is given a namespace, the ambiguity between identically named elements or attributes can be resolved.

A namespace name is a uniform resource identifier (URI). Typically, the URI chosen for the namespace of a given XML vocabulary describes a resource under the control of the author or organization defining the vocabulary, such as a URL for the author’s Web server. However, the namespace specification does not require nor suggest that the namespace URI be used to retrieve information; it is simply treated by an XML parser as a string. For example, the document at http://www.w3.org/1999/xhtml itself does not contain any code. It simply describes the XHTML namespace to human readers. Using a URI (such as “http://www.w3.org/1999/xhtml”) to identify a namespace, rather than a simple string (such as “xhtml”), reduces the probability of different namespaces using duplicate identifiers.

Ref: http://en.wikipedia.org/wiki/XML_namespace

Without futher ado let’s understand with simple example

----------------------
XML (test.xml)
----------------------
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="test.xslt"?>
<root xmlns:h1="http://www.w3.org/h1" xmlns:h2="http://www.w3.org/h2" >
  <h1:one>
    <two h1:attr="h1_attr1" h2:attr="h2_attr1">H1 Test</two>
  </h1:one>
  <h2:one>
    <two  h1:attr="h1_attr2" h2:attr="h2_attr2">H2 Test</two>
  </h2:one>
</root>
----------------------
XSLT (test.xslt) 
----------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:h1="http://www.w3.org/h1" xmlns:h2="http://www.w3.org/h2">
  <xsl:output  method="xml" indent="yes" />
  <xsl:template match="/">
    <root>
      <xsl:apply-templates />
    </root>
  </xsl:template>

  <!-- Template / Function (Easy Understanding -->
  <xsl:template match="h1:one">
    <h1_one>
      <xsl:apply-templates select="two" />
    </h1_one>
  </xsl:template>
  <xsl:template match="h2:one">
    <h1_one>
      <xsl:apply-templates select="two" />
    </h1_one>
  </xsl:template>  
  <xsl:template match="two">
    <xsl:attribute name="h1:attr">
      <xsl:value-of select="@h1:attr" />
    </xsl:attribute>
    <xsl:attribute name="h2:attr">
      <xsl:value-of select="@h2:attr" />
    </xsl:attribute>
    <xsl:value-of select="."/>
  </xsl:template>
</xsl:stylesheet>
----------------------
OUTPUT
----------------------
<?xml version="1.0" encoding="utf-8"?>
<root xmlns:h1="http://www.w3.org/h1" xmlns:h2="http://www.w3.org/h2">
  <test attr="h1_attr1">H1 Test</test>
  <test attr="h1_attr2">H2 Test</test>
</root>

Note:  How apply-templates processes XML Document Very Interesting !!!

Foreach calls GetEnumerator, Current and MoveNext !!!

The foreach statement of the C# language (for each in Visual Basic) hides the complexity of the enumerators.
Therefore, using foreach is recommended instead of directly manipulating the enumerator.

Enumerators can be used to read the data in the collection, but they cannot be used to modify the underlying collection.

Best way to call GetEnumerator using foreach statement

Test with Quick Example

class Program
{        
   static void Main(string[] args)
   {        
      Testing tst = new Testing();
      foreach (var item in tst)
      {
          Console.WriteLine(item);       
      }
   }
}

public class Testing : IEnumerable
{
   public IEnumerator GetEnumerator()
   {
      return (new int[] { 1, 2, 3, 4, 5}).GetEnumerator();
   }
}

Output:
-----------------
1
2
3
4
5
Press any key to continue...

You probably do not want to call GetEnumerator explicitly. Instead it is implicitly called when you use a foreach loop in C#, or a For Each loop in VB.NET.

And all operations GetEnumerator, current, Movenext taken care by foreach, put a debug point and can be seen how foreach take care off all necessary calls

Simple & Quick Example

class Program
{
   static void Main(string[] args)
   {
      Testing tst = new Testing();
      foreach (var item in tst)
      {
          Console.WriteLine(item);
      }
   }
}

public class Testing : IEnumerable
{
   public IEnumerator GetEnumerator()
   {
      return new Testing2();
   }
}

public class Testing2 : IEnumerator
{
   string[] str= { "1", "2", "3", "4", "5","6" };
   int pointer=-1;
   public object Current
   {
      get { return str[pointer]; }
   }

   public bool MoveNext()
   {
      if (pointer < str.Length-1)
      {
          pointer++;
          return true;
      }
      return false;
   }
   public void Reset()
   {
      pointer = 0;
   }
}

What is Remote Attribute?

Underline Problem:-
Any identity thing is unique example userid / emailid / username so to validate uniqueness we have to compare id with existing data
(most obvious database)

Solution:-
Decorating a model property with this attributes will instruct JQuery validate to make an HTTP request to a given action method
for server-side checking. The result is transmitted back to the client and an error message will be displayed before the form is
submitted

We are taking even number example entered at user-end
Create A View

@model MvcApplication1.Controllers.Category
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@{Html.EnableClientValidation(true);}
@using (Html.BeginForm("Create", "Employee", FormMethod.Post))
{
   @Html.ValidationSummary(false)
   @Html.LabelFor(m => m.PIN)
   @Html.TextBoxFor(m => m.PIN, new { maxlength=1  }) <br />        
   <input type="submit" value="Submit" />
}

Create A Model

public class Category
{
   [Remote("IsEvenNumber", "Employee", ErrorMessage = "Enter Even Number")]
   public int PIN { get; set; }
}

Create A Controller

public class EmployeeController : Controller
{
   [HttpGet]
   public ActionResult create()
   {
      return View();
   }
   public JsonResult IsEvenNumber(int PIN)
   {
      return Json(PIN % 2 == 0, JsonRequestBehavior.AllowGet);
   }
}

I can see AJAX request for validation on onkeyup for each character type in textbox
instead of tab (onBlur)

<script language="javascript" type="text/javascript">
$.validator.setDefaults({
onkeyup: false
})
</script>

What is the user of AdditionalFields attributes?

Use to send multiple values to action for validation

------------------------------------------------
Model
------------------------------------------------
public class Category
{
   [Required]
   [Remote("IsEvenNumber", "Employee", AdditionalFields = "hide_pin", ErrorMessage = "Enter Even Number & Not correct pin")]   
   public int PIN { get; set; }
}

------------------------------------------------
View
------------------------------------------------
@model MvcApplication1.Controllers.Category
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<script language="javascript" type="text/javascript">
    $.validator.setDefaults({
        onkeyup: false
    })
</script>

@{Html.EnableClientValidation(true);}
@using (Html.BeginForm("Create", "Employee", FormMethod.Post))
{
    @Html.ValidationSummary(false)

    @Html.LabelFor(m => m.PIN)
    @Html.TextBoxFor(m => m.PIN, new { maxlength = 4 }) <br />

    @Html.Hidden("hide_pin", "10")
    <input type="submit" value="Submit" />
}

------------------------------------------------
Controller
------------------------------------------------
public class EmployeeController : Controller
{
   [HttpGet]
   public ActionResult create()
   {
      return View();
   }

   public JsonResult IsEvenNumber(int PIN, int hide_pin)
   {
      return Json(PIN % 2 == 0 && PIN == hide_pin, JsonRequestBehavior.AllowGet);
   }
}