#30 What is Task?

Task : Task is CLR ThreadPool Component,which manages to execute Operations in parallel.Unlike Thread,they do not create individual thread in windows,instead they utilize the CLR Threads from ThreadPool.

Usage:

They are mainly used when you want to perform Asynchronous Operation.and you have a time consuming block of code which blocks your UI Thread.   

#29: Linq Breaking Deferred Execution.

If you need your Linq Query to be executed Immediately after construction,we can use Conversation Operators like ToList(),ToArray().They force the query to execute immediately

var item = new List<int>();
item.Add(2);
IEnumerable<int> result = item.Select(x =>; x*5).ToList();
//Query is Executed Immedialtely and result will be 10.
//No deferred Execution,because we used ToList(),Forcing query to execute immediately
item.Add(3);
foreach (var VARIABLE in result)
{
 Console.WriteLine(VARIABLE);
}

#28:Deferred Execution-Linq

Most of the Query Operators Execute only when they are enumerated(IEnumerator Type-Move Next),but not when constructed.

var item = new List<int>();
 item.Add(2);
IEnumerable<int> result = item.Select(x => x*5);
//Query is Constructed
item.Add(3);
//But still the item will be added and output would be 10,15 instead of 10.
 //This is called deferred execution.Query executes only on enumerating(for-each) but not on construction.
foreach (var VARIABLE in result)
{
 Console.WriteLine(VARIABLE);
}

Note: Not All Query Operators involves Deferred Execution.For instance First Operator should Execute the Query when constructed and return the First Element.

 

#27:Linq Query Operators

The Query Operators takes the Following delegate Generic Types

1.Tsource-Input sequence.

2.TResult-Output Sequence.

3.TKey-Key used for order,sorting,grouping.

string[] names = { "Rangesh", "Tom", "Jon"};
var outerQuery = names.OrderBy(n2 => n2.Length).Select(n2 => n2.Length).First();

In the above sample,the OrderBy has the Generic delegate type where Source= names and Key=Length

public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector);

#26:Summary of CLR,CTS,CLS,IL

CLR Summary

CLR: A Runtime Environment where all your code get executed as machine instructions.All management of resources,memory,exceptions are taken care by CLR.

CTS: All Types which CLR Supports is exposed by CTS.

CLS:A minimal Support of CTS,which every compiler has to implement it,inorder to Utilize CLR.Intention is to have common feature accross languages,so that they can communicate with each other.  

 

 

 

#20:Abstract Method

1.An Abstract method can be enclosed only in Abstract Class.

class test
 {
 //Error Abstract Method in Non-Abstract Class
 public abstract void hello();
}

2. Abstract Method cannot Declare Body.

abstract class test
{
//Error Abstract Method Cannot have declaration of Body
public abstract void hello()
{
}
// Correct Usage:only contract allowed.
public abstract void hello();
}

3.Abstract Method Cannot be Virtual

 //Abstract method cannot be virtual
  public abstract virtual void h();

4.You must override the Abstract Method in Class you derive.

5.Abstract Class can contain Non-Abstract Methods.

#17 Yield KeyWord

The Yield Keyword Indicates that it is an Iterator. They are used with classes which implements  IEnumerable.

Yield Keyword indicates that you need not write an Explicit Class defining the GetEnumerator Method .In turn the compiler writes it for you.

public IEnumerator GetEnumerator()
 {
 for (int i = 0; i &amp;amp;lt;objarray.Length; i++)
 {
 yield return objarray[(index+i) % objarray.Length];
 }
 }

#16 Enumerating Over Custom Class

To Enumerate over Custom Class,The Class must implement IEnumerable and must have method defined for GetEnumerator.

public class EmployeeArray:IEnumerable
 {
 public int index;
 public Employee[] objarray;
public EmployeeArray(Employee[] Array ,int startindex )
 {
 objarray = Array;
 index = startindex;
 }
public IEnumerator GetEnumerator()
 {
 for (int i = 0; i &lt;;objarray.Length; i++)
 {
 yield return objarray[(index+i) % objarray.Length];
 }
 }