
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