Delegate
delegate string AppendName (string firstName, string lastName);
public static void main(){
AppendName nc = delegate (string firstName, string lastName)
{
var s = sequenceId.ToString();
var zero = string.Empty;
for (var i = 0; i < (5 - s.Length); i++)
{
zero += "0";
}
var serialNumber = $"{eventId.Substring(10, 5)}-{zero}{sequenceId}";
return serialNumber;
};
nc("chamith","saranga");
nc("sajeeka","nanayakkara");
nc("nalaka","gamage");
}
Func (return function)
public static void main(){
Func<string,string> append = (e)=>{
return e.toLower();
};
append("chamith");
}
BookingItems = ((Func<List<BookingItemBo>>) (() =>
{
return result.BookingItem.Select(p => new BookingItemBo(p.ScheduleId, p.SeatNo,
p.BookingItemJourneyInfo.FromCityId, p.BookingItemJourneyInfo.ToCityId,
p.BookingItemJourneyInfo.FromStopId, p.BookingItemJourneyInfo.ToStopId,
p.BookingItemJourneyInfo.JourneyStartDateTime.SpecifiedAsUtc(),
p.BookingItemJourneyInfo.JourneyEndDateTime.SpecifiedAsUtc(),
p.Customer)).ToList();
}))()
Action (void function)
public static void main(){
Action<string> print = (e) =>{
console.WriteLine(e);
};
}
Multiple parameter with Func
Func<int, int, int> getRate = (e,d) => { return 1; };
Pass function as a parameter using lamda expression
static void Main(string[] args)
{
int result = 0;
LamdaExpression(10,15,(e) => { result = e; });
System.Console.WriteLine($"this is lamda expression {result}");
System.Console.Read();
}
static void LamdaExpression(int first,int second,Action<int> abc)
{
abc(first+second);
}
-----------------------------------------------
public class Program
{
static void Main(string[] args)
{
var x = new Process();
x.LongRuniningProcess((int x2)=> {
Console.WriteLine(x2);
});
}
}
public class Process
{
public void LongRuniningProcess(Action<int> callBack)
{
for (int i = 0; i < 10000; i++)
{
Thread.Sleep(100);
//copy file
callBack(i);
}
}
}
=======================================================
Enumerable (create list with some defaults)
{
int result = 0;
LamdaExpression(10,15,(e) => { result = e; });
System.Console.WriteLine($"this is lamda expression {result}");
System.Console.Read();
}
static void LamdaExpression(int first,int second,Action<int> abc)
{
abc(first+second);
}
-----------------------------------------------
public class Program
{
static void Main(string[] args)
{
var x = new Process();
x.LongRuniningProcess((int x2)=> {
Console.WriteLine(x2);
});
}
}
public class Process
{
public void LongRuniningProcess(Action<int> callBack)
{
for (int i = 0; i < 10000; i++)
{
Thread.Sleep(100);
//copy file
callBack(i);
}
}
}
=======================================================
Enumerable (create list with some defaults)
- create List<int> from 0 to 100
IEnumerable<int> arr = Enumerable.Range(0, 100); - create List<T> with some default object.
IEnumerable<Student> str = new Enumerable.Repeate(new Student("CHAMITH"),10);
No comments:
Post a Comment