Monday, 28 October 2013

.Suppose in a scenario if we want to display information only until 5.00 p.m and after that means after 5.00 p.m if any one tries to access the information it should give error message. Then how will you write a event for this ?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Eventanddelegate
{

    public delegate void Time(int t);
   



    class Program
    {
      public static event Time fire;
      public static event Time fire1;


      public void get()
      {
          Console.WriteLine("Enter Time");
          int t = int.Parse(Console.ReadLine());

          if (t <= 5)
          {

              fire(t);
          }
          else
          {
              fire1(t);
              // or
            //  Console.WriteLine("Cannot");
         
          }
     
      }
       
        public void before4(int t)
        {
            Console.WriteLine("time is " + t+"you can perform action");
        }

      public void after4(int t)
      {

          Console.WriteLine("time is " + t+"you cannot perform action");
      }
       
        static void Main(string[] args)
        {

           
            Program p = new Program();
            fire += new Time(p.before4);
            fire1 += new Time(p.after4);
            p.get();


            Console.ReadLine();



        }
    }
}
// This program is created by Jaspreet Singh

0 comments:

Post a Comment