コード例 #1
0
ファイル: Program.cs プロジェクト: taherdev/CSharpForDummies
        // NewEditionPublished - Handler method for the NewEdition event.
        //    Note that the method matches the event's signature.
        void NewEditionPublished(object sender, EventArgs e)
        {
            // Must cast e to get at its contents.
            NewEditionEventArgs ne = (NewEditionEventArgs)e;

            Console.WriteLine("({0}) {1}: {2} - {3}", ne.PubDate, ne.Head,
                              Name, Gripe);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: taherdev/CSharpForDummies
        // Publish - Put out a new edition of the DailyNoise.
        //    This causes the NewEdition event to be raised.
        public void Publish(DateTime date, string majorHeadline)
        {
            Console.WriteLine("Publication: {0}, {1}", date, majorHeadline);
            // Set up the event arguments.
            NewEditionEventArgs e = new NewEditionEventArgs(date, majorHeadline);

            // Call our "event raiser" method.
            OnNewEdition(e);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: taherdev/CSharpForDummies
        // Main()'s handler method for the NewEdition event.
        static void DailyNoise_NewEdition(object sender, EventArgs e)
        {
            // Cast sender if you need information from the sending object.
            Publisher pub = (Publisher)sender;
            // Cast e if you need additional arguments with the event.
            NewEditionEventArgs ne = (NewEditionEventArgs)e;

            Console.WriteLine("({0}) {1}: {2} - {3}", ne.PubDate, ne.Head,
                              pub.Name, "Ah, the paper's on my roof again!");
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: hbumadian/CSharpForDummies
 // OnNewEdition - This method takes the correct steps to
 //    safely raise the NewEdition event.
 //    Note: Always provide an OnXXX event raiser method.
 protected virtual void OnNewEdition(NewEditionEventArgs e)
 {
   // Save a copy (for safety in multithreaded programs).
   EventHandler<NewEditionEventArgs> temp = NewEdition;
   // Make sure there are subscribers to the event.
   if (temp != null)
   {
     // Actually raise the event.
     // 'this' is the Publisher object.
     temp(this, e);
   }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: taherdev/CSharpForDummies
        // OnNewEdition - This method takes the correct steps to
        //    safely raise the NewEdition event.
        //    Note: Always provide an OnXXX event raiser method.
        protected virtual void OnNewEdition(NewEditionEventArgs e)
        {
            // Save a copy (for safety in multithreaded programs).
            EventHandler <NewEditionEventArgs> temp = NewEdition;

            // Make sure there are subscribers to the event.
            if (temp != null)
            {
                // Actually raise the event.
                // 'this' is the Publisher object.
                temp(this, e);
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: hbumadian/CSharpForDummies
 // Publish - Put out a new edition of the DailyNoise.
 //    This causes the NewEdition event to be raised.
 public void Publish(DateTime date, string majorHeadline)
 {
   Console.WriteLine("Publication: {0}, {1}", date, majorHeadline);
   // Set up the event arguments.
   NewEditionEventArgs e = new NewEditionEventArgs(date, majorHeadline);
   // Call our "event raiser" method.
   OnNewEdition(e);
 }