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?
Func<string, string, string>
is not a "problem". – DoggedFunc<string, string>
doesn't take two strings, it takes a single string - and it's really unclear whereFirstName
andLastName
would come in here. You could create aFunc<string>
that returnedFirstName + " " + LastName
, but that's not the same thing at all, as it has no inputs. – Radmanmodel.FunctTest("unclear")
for example? – RadmanFunc<string, string, string> FullName = (first, last) => first + last;
Usage:FullName(FirstName, LastName)
Pretty much the same as how you would do delegates just more fancy. – Officious