Karatas, FERHAT
I would love to change the world, but they won't give me the source code!
Lambda Expression
23.5.2009 13:39:41 - Filed under : C# | LINQ
Lambda Expressions provide a more concise,  functional syntax for writing anonymous methods.  They end up being  super useful when writing LINQ query expressions - since they provide a  very compact and type-safe way to write functions that can be passed as  arguments for subsequent evaluation. 
Sample 1 : 
public class Person
  public string FirstName;
  public string LastName;
  public int Age;

List<person> people = new List<person>
    new Person{FirstName = "Ferhat", LastName = "Karatas", Age=10},
    new Person{FirstName = "Elif", LastName = "Sila", Age=5},
    new Person{FirstName = "Sevim", LastName = "Karatas", Age=15}
// return all Karatas
IEnumerable<person> results = people.Where(p => p.LastName == "Karatas");
double averageAge = people.Average(p => p.Age);
Label1.Text = results.Count().ToString() + "-" + averageAge.ToString();

Sample 2 :

var numbers = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
var evennumber = numbers.FindAll(p => p % 2 == 0);
foreach (int item in evennumber)
    Label1.Text += item + "-";

The p => expressions highlighted above  in red are Lambda expressions.  In the sample above I'm using the first  lambda to specify the filter to use when retrieving people, and the  second lambda to specify the value from the Person object to use when  computing the average.

Keywords : Linq, lambda expression
with 0 comments

LINQ Installation
5.3.2007 15:55:21 - Filed under : LINQ
The extensibility of the query architecture is used in the LINQ project itself to provide implementations that work over both XML and SQL data. The query operators over XML (XLinq) use an efficient, easy-to-use in-memory XML facility to provide XPath/XQuery functionality in the host programming language. The query operators over relational data (DLinq) build on the integration of SQL-based schema definitions into the CLR type system. This integration provides strong typing over relational data while retaining the expressive power of the relational model and the performance of query evaluation directly in the underlying store.

You can download latest version (May 2006 CTP) of LINQ here

You can open LINQ project after install downloaded files as below:
File - New - Project - LINQ Preview (under Visual C# tab) 

Also you can find the technical article about C# 3.0 here and download the word document here.

Keywords : LINQ, XLinq, DLinq, C# 3.0, May 2006 CTP

with 0 comments

Previous | Next
Current Page: 1