return method c# code example
Example 1: c# function return
static string lastFirst(string firstName, string lastName)
{
string separator = ", ";
string result = lastName + separator + firstName;
return result;
}
Example 2: how to return a value in c#
void Start()
{
Debug.Log(Message());
}
string Message()
{
string message = "Hello world";
return message;
}
Example 3: what is a return statement C#
Example 4: how to call a method from a class in c#
using System;
namespace CalculatorApplication {
class NumberManipulator {
public int FindMax(int num1, int num2) {
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}
static void Main(string[] args) {
int a = 100;
int b = 200;
int ret;
NumberManipulator n = new NumberManipulator();
ret = n.FindMax(a, b);
Console.WriteLine("Max value is : {0}", ret );
Console.ReadLine();
}
}
}
Example 5: c# get the return value of a func
Func<int> function;
int returnValue;
function = () => 0;
returnValue = function();