Answer to Question #345355 in C# for KAY

Question #345355

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

1
Expert's answer
2022-05-27T09:39:40-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS