Last active
April 5, 2016 16:26
-
-
Save fcmendoza/791801ce7772c265f33999756686a8f4 to your computer and use it in GitHub Desktop.
Understanding how Func<T> works.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Program | |
{ | |
public static void Main() { | |
new Functions().Start(); | |
} | |
} | |
public class Functions | |
{ | |
public void Start() | |
{ | |
var step = new ServiceInitializationStep ( | |
() => "this is a string", | |
() => "this is another string", | |
(number) => "this is yet another string " + number.ToString() | |
); | |
step.PrintData(); | |
} | |
} | |
public class ServiceInitializationStep | |
{ | |
public ServiceInitializationStep(Func<string> securedString, Func<string> securedConnectionString, Func<int, string> securedNewConnectionString) | |
{ | |
_securedString = securedString; | |
_securedConnectionString = securedConnectionString; | |
_securedNewConnectionString = securedNewConnectionString; | |
} | |
public void PrintData() { | |
Console.WriteLine("test"); | |
Console.WriteLine(_securedString()); | |
Console.WriteLine(_securedConnectionString()); | |
Console.WriteLine(_securedNewConnectionString(100)); | |
} | |
private Func<string> _securedString { get; set; } | |
private Func<string> _securedConnectionString { get; set; } | |
private Func<int, string> _securedNewConnectionString { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here we can see this code running on https://dotnetfiddle.net/lJykOK