Tuesday, December 7, 2010

Notepad - Right to Left

Today, while typing in notepad I faced a strange problem, my typing order just got reversed. I was typing fro m left to write and it changed to right to left. After some googling i found that it  is due to s accidental pressing of notepad shortcut Cntrl+RightShift.

So if You want to right to left in Notepad then use shortcut:
Cntrl+RightShift Key

if You want to left to right in Notepad then use shortcut:
Cntrl+LeftShift Key

As per following Wiki Link:
http://en.wikipedia.org/wiki/Notepad_%28software%29
Notepad supports both left-to-right and right-to-left based languages, and one can alternate between these viewing formats by using the right or left Ctrl+Shift keys to go to right-to-left format or left-to-right format, respectively.

Monday, December 6, 2010

LINQ - Beginners Tutorial-2

Here we will start using some advance operators and will write code as lambda expressions as well as comprehension query.

Input:
string[] names = { "Ajay", "Vijay", "Karan", "Farhan", "Pooja", "Geeta", "Dia" };

Lambda Expression:
IEnumerable tp = names.Where(n => n.EndsWith("a"))
                            .OrderBy(n=> n.Length)
                            .Select(n => n.ToUpper());


Comprenesion Query:
IEnumerable tp = from n in names
                         where n.EndsWith("a")
                         orderby n.Length
                         select n.ToUpper();  
 

Enumerate result:
foreach (string str in tp)
{
     Console.WriteLine(str);
}


Output:
DIA
POOJA
GEETA

Main Points:
1. We have option to use either lambda expressions or comprehension query to get the desired result.
2. Compiler converts comprehension query to lambda expression.

Sunday, December 5, 2010

LINQ - Beginners Tutorial-1

What is LINQ?
LINQ stands for Language integrated Query, that allows us to query local object collection or remote data source.

Using LINQ we can query any collection implementing IEnumaerable interface. To use LINQ in code we need to use Sysrtem.Linq namespace.

First Example:
string[] names = { "Ajay", "Vijay", "Karan", "Farhan", "Pooja", "Geeta" };
IEnumerable tp = names.Where(n => n.EndsWith("a"));
foreach (string str in tp)
{
Console.WriteLine(str);
}


Here we have taken a string array in first line of code, fnames that contains 6 names.
In second line of code we write a Linq to get the names ending with "a".

Output:
Pooja
Geeta

Main Points:
1. Linq data has two parts, sequence and elements. Here names is a sequence and array members are elements.
2. Linq doesn't alter the input sequence. So result will always be in the order it was input.
3. Linq always return an IEnumerable result.
4. "n => n.EndsWith("a")" is a lambda expression that filters the result for us.