Question #345355

.Create a delegates that accepts a number from user and displays whether the number is even or odd.

Expert's answer

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();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS