Without parameters C# with Example



Without parameters C# with Example

This example shows how to create a delegate that encapsulates the method that returns the current time 
static DateTime UTCNow() 
{ 
return DateTime.UtcNow; 
} 
static DateTime LocalNow() 
{ 
return DateTime.Now; 
} 
static void Main(string[] args) 
{ 
Func method = UTCNow; 
// method points to the UTCNow method 
// that retuns current UTC time 
DateTime utcNow = method(); 
method = LocalNow; 
// now method points to the LocalNow method 
// that returns local time 
DateTime localNow = method(); 
} 

0 Comment's

Comment Form

Submit Comment