xxxxxxxxxx
void Start()
{
Debug.Log(Message()/*calling the function with its name*/);
}
string Message()/*you can make values to functions with () and {}*/
{
string message = "Hello world";
return message;//this says which value will be returned
}
xxxxxxxxxx
// To create a function with a return value, note the variable
// type in front of the function name and add a return of the
// same type at the end.
static string lastFirst(string firstName, string lastName)
{
string separator = ", ";
string result = lastName + separator + firstName;
return result;
}
xxxxxxxxxx
public void DoSomething() // Action
public void DoSomething(int number) // Action<int>
public void DoSomething(int number, string text) // Action<int, string>
public int DoSomething() // Func<int>
public int DoSomething(float number) // Func<float, int>
public int DoSomething(float number, string text) // Func<float, string, int>
xxxxxxxxxx
Func<int> function;
int returnValue;
function = () => 0;
returnValue = function();
xxxxxxxxxx
int cubedNumber = cube(5);
Console.WriteLine(cubedNumber);
Console.ReadLine();
static int cube(int num)
{
int result = num * num * num;
return result;
}