When View Engine come into picture in MVC Lifecycle ?

When we are ready to render a view after execution of controller logic View Engine is involved.The execution of the View Result involves the selection of the appropriate View Engine to render the View Result. If ActionResult returns a ViewResult, execution pipeline selects appropriate ViewEngine to render ViewResult. It is taken care by view engine’s interface IviewEngine.

To improve performance we should remove all ViewEngine that is not needed.
protected void Application_Start()
{
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
}

What is Early binding and late binding

Early binding also known as compile time polymorphism or method overloading.
In OverLoading – We have same class, different parameters and same method name.

Late binding also known as dynamic polymorphism or method overriding and is achieved through parent and child classes by virtual keyword.
In Overriding – We have same method name,same parameters but different classes.

What is Task in c#

.Net framework provides System.Threading.Tasks.Task class to let you create threads and run them asynchronously.

using System;
using System.Threading.Tasks;

namespace TaskExample
{
public static class TaskProgram
{
    public static void Main()
        {
            Task t = Task.Run(() =>
            {
            for (int x = 0; x < 50; x++)
            {
            Console.Write(“Hi “);
            }
            });
            t.Wait();
        }
  }

}

Yield keyword in c#

The yield keyword effectively creates a lazy enumeration over collection items that can be much more efficient. 

Traditional way to return Ienumerator

IEnumerable<int> getnumber()
{
var i = 0; var list = new List<int>();
while (i<5)
list.Add(++i); return list;
}
foreach(var number in getnumber()) Console.WriteLine(number);

Loop with Yield

IEnumerable<int> getnumber()
{
var i = 0;
while (i<5) yield return ++i;
}
foreach(var number in getnumber()) Console.WriteLine(number);

Select and deselect all checkbox in table in jquery

We have a checkboz having id=selectall on selecting/deselecting we check/uncheck all check box in table whose clas=”checkbox”

$(function(){

// add multiple select / deselect functionality
$(“#selectall”).click(function () {
$(‘.checkbox’).attr(‘checked’, this.checked);
});

// if all checkbox are selected, check the selectall checkbox

$(“.checkbox”).click(function(){

if($(“.checkbox”).length == $(“.case:checked”).length) {
$(“#selectall”).attr(“checked”, “checked”);
} else {
$(“#selectall”).removeAttr(“checked”);
}

});
});

Sort a numeric array from small to largest in jquery

numArray.sort((a, b) => a – b); // For ascending sort numArray.sort((a, b) => b – a); // For descending sort

But above code will work only on ES6,6 supporting browser If you want to work in Old browser as well use below code.

 
<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array Sort</h2>

<p>The sort() method sorts an Numeric array .</p>

<button onclick=”myFunction()”>Try it</button>

<p id=”demo”></p>

var array1 = [1, 30, 4, 21,0,12,21,11,456];
function myFunction() {
array1.sort(compareNumbers);
document.getElementById(“demo”).innerHTML = array1;
}
function compareNumbers(a, b)
{
return a – b;
}

</body>
</html>