.Create a delegates that accepts a number from user and displays whether the number is even or odd.
using System;
delegate void VoidDelegate();
class Program
{
static void isEvenOrOdd()
{
string str;
int value;
Console.Write("Please enter a number:");
str = Console.ReadLine();
if (int.TryParse(str, out value))
if (value % 2 == 0)
Console.WriteLine("number is even");
else if (value % 2 == 1)
Console.WriteLine("number is odd");
}
static void Main(string[] args)
{
VoidDelegate myDelegate = new VoidDelegate(isEvenOrOdd);
myDelegate();
}
}
Comments
Leave a comment