[program-l] Re: C# Help Please

  • From: David Lant <david.lant@xxxxxxxxxxxx>
  • To: "'program-l@xxxxxxxxxxxxx'" <program-l@xxxxxxxxxxxxx>
  • Date: Mon, 21 Mar 2005 13:24:35 -0000

Hi Ian,

Snap! <smile>  I think I'm pretty much OK with the concepts of delegates and
events.  The problem I'm having is getting them to work properly across
domain, and more specifically machine boundaries.

So, are you saying that if the Submission event had been declared simply as
an event, and had not been typed using the delegate, then C# would have
returned Null in the If statement?  If so, I can't think of any VB
equivalent to test for that.  However, since the same application is
declaring the event anyway, it seems a tad overkill to check to see if it's
been declared properly before raising the event.  I know Mark just gave us
plenty of reasons why double-checking stuff can be a good thing, but
normally that's if you're receiving information from outside the domain.  It
would be the equivalent of doing...

Dim intNumber As Integer

If TypeOf intNumber Is Integer Then
...
End If

Hmm, in fact, maybe I could give the TypeOF keyword a try to see what it
returns from an event. <smile>

Thanks for the suggestion.

David Lant

I.T. Consultant 
Consultancy & Development
ICT Services
Tel: (01392) 382464

Devon County Council accepts no legal responsibility for the contents of
this message. The views expressed do not reflect those of Devon County
Council.


-----Original Message-----
From: Ian Sharpe [mailto:isforums@xxxxxxxx] 
Sent: 21 March 2005 12:55
To: program-l@xxxxxxxxxxxxx
Subject: [program-l] Re: C# Help Please


Hi David,

Submission is defined as an Event. I think the test in the C# code is to see
whether an event handler has been assigned to this event. I think that in C#
this is how you test for this.

The test you are performing in VB.NET is simply  attempting to call this
event directly. I think you need to find out how you test whether an event
handler has been assigned to an event?

Sorry to be so vague but I'm still trying to get my head around delogates
and events!

Cheers
Ian

----- Original Message ----- 
From: "David Lant" <david.lant@xxxxxxxxxxxx>
To: <Program-L@xxxxxxxxxxxxx>
Sent: Monday, March 21, 2005 11:40 AM
Subject: [program-l] C# Help Please


> Hi all,
>
> Could someone familiar with C# let me know what the following code means
> please?   I'm trying to reproduce it in VB.NET.
>
> if (Submission != null)
> {
> Console.WriteLine("Broadcasting...");
> // Raise Event. This calls the remote listening
> method on all clients of this object.
> Submission(this, e);
> }
>
> When I try to code what I believe to be the VB equivalent:
>
> If Submission <> Nothing Then
> Console.WriteLine("Broadcasting...")
> Raise Submission(Me, e)
> End If
>
> I get the following error against the If statement:
>
> 'Public Event Submission(sender As Object, SubmitArgs As SubmitEventArgs)'
> is an event, and cannot be called directly. Use a 'RaiseEvent' statement
to
> raise an event.
>
> Which does make sense to me.  So I'm unclear as to how C# can reference an
> event like this, while VB cannot.  Have I misinterpreted the statement?
Is
> it that VB simply doesn't need to do this and can raise the event
> unconditionally?
>
> Thanks for any clarification that might be available.
>
> David Lant
>
> I.T. Consultant
> Consultancy & Development
> ICT Services
> Tel: (01392) 382464
>
> Devon County Council accepts no legal responsibility for the contents of
> this message. The views expressed do not reflect those of Devon County
> Council.
>
> ** To leave the list, click on the immediately-following link:-
> ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
> ** If this link doesn't work then send a message to:
> ** program-l-request@xxxxxxxxxxxxx
> ** and in the Subject line type
> ** unsubscribe
> ** For other list commands such as vacation mode, click on the
> ** immediately-following link:-
> ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
> ** or send a message, to
> ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: