Answer to Question #345354 in C# for nicky

Question #345354

1. Create a delegate that displays a message (" you are underage" ) if the user's age is less than 18 and (you qualify to be an adult") if the age is greater than 18.



1
Expert's answer
2022-05-30T08:15:22-0400
using System;
delegate string StringDelegate(int age);
class Program
{
    static string ConfirmAge(int age)
    {
        if (age < 18)
            return "you are underage";
        else
            return "you qualify to be an adult";
    }
    static void Main(string[] args)
    {
        string str;
        int age;
        StringDelegate myDelegate = new StringDelegate(ConfirmAge);
        Console.Write("Please enter you age:");
        str = Console.ReadLine();
        if (int.TryParse(str, out age))
            Console.WriteLine(myDelegate(age));
    }
}

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