Step 1: Define the Function
In C#, defining a function involves specifying its return type, name, and parameters inside parentheses. Here’s how you can define a function to add two numbers:
C#
using System;
public class Program
{
public static void Main()
{
// Example usage:
int result = AddNumbers(5, 3);
Console.WriteLine("Sum is: " + result);
}
// Function to add two numbers
public static int AddNumbers(int a, int b)
{
int sum = a + b;
return sum;
}
}