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.
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));
}
}
Comments
Leave a comment