//The "void" in this instance refers to the return type of this function//This function won't have a return value.voidfunctionName(int parameter){//Code you want to run}//Calls the code in the functionfunctionName(Aninteger)
//Func is a invokeable container for Mehod or function method //that returns something. They can accept inputs based on the generals //that you template on and reserve the last general template for the return. //If you do not need a return or wish to return nothing check out the Action Class//example:
Func<string/*Or some other type to return*/> YourFuncProperty
=newFunc(()=>{/*do something*/return"or return what you want";});//or
Func<string/*Or some other type to return*/> YourFuncProperty
=()=>{/*do something*/return"or return what you want";};//for a paramiterized func
Func<int/*Or some other types followed by others optional comma seperated*/,string/*Or some other type to return last*/> YourParamitarizedFuncProperty =(x/*Each Param will be to the comma seperated types*/)=>{/*do some with the inputs*/return$"you entered a {x} or return what you want";};// you can invloke them by calling their invokes.string YouReturn = YourFuncProperty.Invoke();string YouReturn = YourParamitarizedFuncProperty.Invoke(5);//The last is the basic sycronous way. For a aysnc call uses
YourFuncProperty.BeginInvoke();
YourParamitarizedFuncProperty.BeginInvoke(5);//however, you will need to begin a await with EndInvoke to get your result after.string YouReturn = YourFuncProperty.EndInvoke();string YouReturn = YourParamitarizedFuncProperty.EndInvoke(5);//You can also fill them with defined methods in a class if you wish, //but the signatures must match.Func<string> YourActionDefinedProperty = YourDefinedMethod;stringYourDefinedMethod(){//do somethingreturn"or return what you want";}//Example of usepublicsealedclassDataContainer{//A bit contrived but we will give the ablity to overide the printout //of the class while still keeping it sealed. See the invoke at ToString.//could be useful in a library or something?staticfunc<string> SealedFuncStringOverride;DataContainer(datetime Date){this.Date = Date;}publicdatetime Date {get;privateset;}publicint Amount {get;privateset;}publicstring Info {get;privateset;}publicstring FirstName {get;privateset;}//The invoke is used in here.publicoverridestringToString(){if(SealedFuncStringOverride!=null)return SealedFuncStringOverride.BeginInvoke();returnbase.ToString;}}
// In C#, this is how we define a function:/*
In this case, the function is called 'myFunction', it takes
1 parameter which is an integer and doesn't return anything (void).
*/staticvoidmyFunction(int a){// INSERT CODE HERE
Console.WriteLine(a);}
usingSystem;usingSystem.Collections.Generic;usingstaticSystem.Console;namespaceCSFlow.Delegates.Others{publicclassActionFunc{publicstaticvoid Run (){// Example of : Action// Use action when a mathod return voidAction<string> display =newAction<string>(DisplayMessage);display("Calculate Discount :");// Example of : Func// Use action when a mathod return valueFunc<double,double> discount =newFunc<double,double>(Discount);display(discount(12.5).ToString());List<Customer> custList =newList<Customer>();
custList.Add(newCustomer{ Id =1, FirstName ="Joydip", LastName ="Kanjilal", State ="Telengana", City ="Hyderabad", Address ="Begumpet", Country ="India"});
custList.Add(newCustomer{ Id =2, FirstName ="Steve", LastName ="Jones", State ="OA", City ="New York", Address ="Lake Avenue", Country ="US"});
custList.Add(newCustomer{ Id =3, FirstName ="Sefat", LastName ="Anam", State ="OSA", City ="New York", Address ="Manhatten", Country ="US"});// Example of : Predicate// Use Predicate for search dataPredicate<Customer> FindAddress = customer => customer.Address =="Manhatten";Customer searchData = custList.Find(FindAddress);display($"{searchData?.FirstName}{searchData?.LastName} From - {searchData?.City} ");ReadKey();}staticvoid DisplayMessage (string message){WriteLine(message);}staticdouble Discount (double money){return money *.5;}classCustomer{publicint Id {get;set;}publicstring FirstName {get;set;}publicstring LastName {get;set;}publicstring Address {get;set;}publicstring City {get;set;}publicstring State {get;set;}publicstring Country {get;set;}}}}
publicvoidSayHello(string name){
Console.WriteLine("Hello");}publicvoidSayName(){
Console.WriteLine("What is your name?");string name = Console.ReadLine();SayHello(name);}