Click here to Skip to main content
15,923,557 members
Home / Discussions / C#
   

C#

 
QuestionAbout dateTimePicker problem Pin
miss YY26-Nov-09 18:01
miss YY26-Nov-09 18:01 
AnswerRe: About dateTimePicker problem Pin
avigodse26-Nov-09 18:56
professionalavigodse26-Nov-09 18:56 
AnswerRe: About dateTimePicker problem Pin
Shameel26-Nov-09 20:05
professionalShameel26-Nov-09 20:05 
AnswerRe: About dateTimePicker problem Pin
ScottM126-Nov-09 22:13
ScottM126-Nov-09 22:13 
GeneralRe: About dateTimePicker problem Pin
PIEBALDconsult27-Nov-09 2:59
mvePIEBALDconsult27-Nov-09 2:59 
QuestionRe: About dateTimePicker problem Pin
ScottM127-Nov-09 3:04
ScottM127-Nov-09 3:04 
AnswerRe: About dateTimePicker problem Pin
PIEBALDconsult27-Nov-09 4:45
mvePIEBALDconsult27-Nov-09 4:45 
QuestionDelegates and Events Pin
BobInNJ26-Nov-09 12:51
BobInNJ26-Nov-09 12:51 
I am trying to understand delegates and events in C Sharp. I am finding the subject confusing. Please consider the following program:

<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
<br />
public class StockArgs : EventArgs {<br />
    public StockArgs( String symbol, string price, int volume )<br />
    {<br />
        this.symbol = symbol;<br />
        this.price = Decimal.Parse(price);<br />
        this.volume = volume;<br />
    }<br />
    public string Symbol {<br />
        get<br />
        { return symbol; }<br />
    }<br />
    public string Price {<br />
        get<br />
        { return Price; }<br />
    }<br />
<br />
    private string symbol;<br />
    private decimal price;<br />
    private int volume;<br />
}<br />
<br />
public class Stock {<br />
    public delegate void StockPiraceAlertHandler( object source, StockArgs a);<br />
    public event StockPiraceAlertHandler OnAlert;<br />
<br />
    public delegate void VolumeAlertHandler(object source, StockArgs a);<br />
    public event VolumeAlertHandler OnVolumeAlert;<br />
<br />
    public void Alert()<br />
    {<br />
        if ( OnAlert != null )<br />
            OnAlert( this, new StockArgs("ORCL", "14.50", 100000) );<br />
    }<br />
<br />
}<br />
<br />
public class Main {<br />
    public static void Main()<br />
    {<br />
        Stock stock1 = new Stock();<br />
        stock1.OnAlert(null, null);<br />
    }<br />
}


In the main routine (called Main) I want to trigger the alert called OnAlert. However, the code does not compile. Furthermore, the compiler error message implies that alerts can be only generated by the class that defines the alert. If that is true, then it seems like a major deficiency with alerts in C sharp. However, I suspect I am missing one or more key points. Please enlighten me.

I thank the group in advance for their responses.

Bob
AnswerRe: Delegates and Events Pin
Luc Pattyn26-Nov-09 13:08
sitebuilderLuc Pattyn26-Nov-09 13:08 
AnswerRe: Delegates and Events Pin
Yuri Vital26-Nov-09 13:16
Yuri Vital26-Nov-09 13:16 
AnswerRe: Delegates and Events Pin
PIEBALDconsult26-Nov-09 15:11
mvePIEBALDconsult26-Nov-09 15:11 
AnswerRe: Delegates and Events Pin
N a v a n e e t h26-Nov-09 16:42
N a v a n e e t h26-Nov-09 16:42 
GeneralRe: Delegates and Events Pin
Yuri Vital26-Nov-09 20:59
Yuri Vital26-Nov-09 20:59 
GeneralRe: Delegates and Events Pin
N a v a n e e t h27-Nov-09 0:22
N a v a n e e t h27-Nov-09 0:22 
Questionanother web browser control?!! Pin
Jassim Rahma26-Nov-09 11:56
Jassim Rahma26-Nov-09 11:56 
AnswerRe: another web browser control?!! Pin
Abhishek Sur26-Nov-09 12:01
professionalAbhishek Sur26-Nov-09 12:01 
GeneralRe: another web browser control?!! Pin
Jassim Rahma26-Nov-09 12:08
Jassim Rahma26-Nov-09 12:08 
AnswerRe: another web browser control?!! Pin
ScottM126-Nov-09 22:14
ScottM126-Nov-09 22:14 
QuestionWindows Forms Context Menu Spacer Pin
Jammer26-Nov-09 9:43
Jammer26-Nov-09 9:43 
AnswerRe: Windows Forms Context Menu Spacer Pin
DaveyM6926-Nov-09 9:48
professionalDaveyM6926-Nov-09 9:48 
GeneralRe: Windows Forms Context Menu Spacer Pin
Jammer26-Nov-09 10:34
Jammer26-Nov-09 10:34 
GeneralRe: Windows Forms Context Menu Spacer Pin
DaveyM6926-Nov-09 10:48
professionalDaveyM6926-Nov-09 10:48 
GeneralRe: Windows Forms Context Menu Spacer Pin
Jammer26-Nov-09 10:50
Jammer26-Nov-09 10:50 
QuestionMultithreading C# Pin
J imran26-Nov-09 6:09
J imran26-Nov-09 6:09 
AnswerRe: Multithreading C# Pin
Ravi Bhavnani26-Nov-09 6:28
professionalRavi Bhavnani26-Nov-09 6:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.