func trong c# code example
Example 1: c# funtion
public int AddNumbers(int number1, int number2){ int result = number1 + number2; if(result > 10) { return result; } return 0;}
Example 2: C# func
Func<string> YourFuncProperty
= new Func(()=>{ return "or return what you want";});
Func<string> YourFuncProperty
= ()=>{return "or return what you want";};
Func<int
,
string> YourParamitarizedFuncProperty =
(x)=>
{return $"you entered a {x} or return what you want";};
string YouReturn = YourFuncProperty.Invoke();
string YouReturn = YourParamitarizedFuncProperty.Invoke(5);
YourFuncProperty.BeginInvoke();
YourParamitarizedFuncProperty.BeginInvoke(5);
string YouReturn = YourFuncProperty.EndInvoke();
string YouReturn = YourParamitarizedFuncProperty.EndInvoke(5);
Func<string> YourActionDefinedProperty = YourDefinedMethod;
string YourDefinedMethod()
{
return "or return what you want";
}
public sealed class DataContainer
{
static func<string> SealedFuncStringOverride;
DataContainer(datetime Date)
{
this.Date = Date;
}
public datetime Date {get; private set;}
public int Amount {get; private set;}
public string Info {get; private set;}
public string FirstName {get; private set;}
public override string ToString()
{
if(SealedFuncStringOverride!=null)
return SealedFuncStringOverride.BeginInvoke();
return base.ToString;
}
}