Difference between lambda expression and Icompairable [Resolved]

Posted by Muhsinathk under ASP.NET on 9/18/2012 | Points: 10 | Views : 1424 | Status : [Member] | Replies : 4
Hi,
What is the difference between lambda expression and Icompairable?




Responses

Posted by: Vikash on: 9/18/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Lambda expression allows us to pass functions as arguments to a method call or we can say inline definition of a method

public static void SimpleLambdExpression()
{
List<int> numbers = new List<int>{1,2,3,4,5,6,7};
var evens = numbers.FindAll(n => n % 2 == 0);
var evens2 = numbers.FindAll((int n) => { return n % 2 == 0; });
ObjectDumper.Write(evens);
ObjectDumper.Write(evens2);
}


An IComparable allow a class to perform comparision on properties

look at the following code..
class Employee : IComparable<Employee>
{
public int Salary { get; set; }
public string Name { get; set; }

public int CompareTo(Employee other)
{
// Alphabetic sort if salary is equal. [A to Z]
if (this.Salary == other.Salary)
{
return this.Name.CompareTo(other.Name);
}
// Default to salary sort. [High to low]
return other.Salary.CompareTo(this.Salary);
}

public override string ToString()
{
// String representation.
return this.Salary.ToString() + "," + this.Name;
}
}

for more follow this link below-
http://www.dotnetperls.com/icomparable

Regards,
Vikash Pathak

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/18/2012 [Member] Bronze | Points: 25

Up
0
Down
Thank you Vikash

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/18/2012 [Member] Starter | Points: 25

Up
0
Down
Good Job Vikash

Thanks & Regards
Hari

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vikash on: 9/18/2012 [Member] Starter | Points: 25

Up
0
Down
Please mark as answer if u got helpful..............

Regards,
Vikash Pathak

Muhsinathk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response