Reputation: 4124
How can I pass e.g 2 strings to Func and return a string? Let say I would like to pass FirstName and LastName and the result should be like FirstName + LastName;
Moreover, I would like to have a Func declared as a property.
Please take a look at my code:
public class FuncClass
{
private string FirstName = "John";
private string LastName = "Smith";
//TODO: declare FuncModel and pass FirstName and LastName.
}
public class FuncModel
{
public Func<string, string> FunctTest { get; set; }
}
Could you please help me to solve this problem?
Upvotes: 6
Views: 13329
Reputation: 151
This should do the trick:
public class FuncModel
{
//Func syntax goes <input1, input2,...., output>
public Func<string, string, string> FunctTest { get; set; }
}
var funcModel = new FuncModel();
funcModel.FunctTest = (firstName, lastName) => firstName + lastName;
Console.WriteLine(funcModel.FuncTest("John", "Smith"));
Upvotes: 9