By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,917 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,917 IT Pros & Developers. It's quick & easy.

Can I have an Event & Method with the same name?

P: n/a
Can I have an Event & Method with the same name in the same class? I want
to have a "Close" method to close a socket and a "Close" event to be raised
when the socket is closed.
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Terry Olsen" <to******@hotmail.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
Can I have an Event & Method with the same name in the same class? I want
to have a "Close" method to close a socket and a "Close" event to be raised when the socket is closed.


Even if you could, it's not a good idea. Why chance the unneccessary
confusion when you can use a similar meaningful name instead - SocketClosed,
CloseSocket, etc?
Nov 21 '05 #2

P: n/a
Why not call them something like
MyMethodName
MyMethodNameEvent
--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Ged Mead" <ge*********@tesco.net> wrote in message
news:Zz**********@newsfe1-gui.ntli.net...

"Terry Olsen" <to******@hotmail.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
Can I have an Event & Method with the same name in the same class? I
want
to have a "Close" method to close a socket and a "Close" event to be

raised
when the socket is closed.


Even if you could, it's not a good idea. Why chance the unneccessary
confusion when you can use a similar meaningful name instead -
SocketClosed,
CloseSocket, etc?

Nov 21 '05 #3

P: n/a
The reason I asked is because I am trying to write a "WinSock" class with
the same properties, methods, and events as the VB6 WinSock Control, which
has the same name for the Close Event & Method.
"Ged Mead" <ge*********@tesco.net> wrote in message
news:Zz**********@newsfe1-gui.ntli.net...

"Terry Olsen" <to******@hotmail.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
Can I have an Event & Method with the same name in the same class? I
want
to have a "Close" method to close a socket and a "Close" event to be

raised
when the socket is closed.


Even if you could, it's not a good idea. Why chance the unneccessary
confusion when you can use a similar meaningful name instead -
SocketClosed,
CloseSocket, etc?

Nov 21 '05 #4

P: n/a
The answer is no. You cannothave the same identifier for two different
types. With functions and subs though you can overload the identifier as
long as the signatyures are different.

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Terry Olsen" <to******@hotmail.com> wrote in message
news:eJ**************@TK2MSFTNGP12.phx.gbl...
The reason I asked is because I am trying to write a "WinSock" class with
the same properties, methods, and events as the VB6 WinSock Control, which
has the same name for the Close Event & Method.
"Ged Mead" <ge*********@tesco.net> wrote in message
news:Zz**********@newsfe1-gui.ntli.net...

"Terry Olsen" <to******@hotmail.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
Can I have an Event & Method with the same name in the same class? I
want
to have a "Close" method to close a socket and a "Close" event to be

raised
when the socket is closed.


Even if you could, it's not a good idea. Why chance the unneccessary
confusion when you can use a similar meaningful name instead -
SocketClosed,
CloseSocket, etc?


Nov 21 '05 #5

P: n/a
Terry,
Can I have an Event & Method with the same name in the same class? No as they are both at the same scope.
I want to have a "Close" method to close a socket and a "Close" event to
be raised when the socket is closed. I would call the event Closed, while calling the method Close. (which btw is
what you stated :-))

If I needed an event that occurred when the connection was about to close I
would call it Closing.

Which is what the "Design Guidelines for Class Library Developers"
recommends:

http://msdn.microsoft.com/library/de...Guidelines.asp

http://msdn.microsoft.com/library/de...Guidelines.asp

Hope this helps
Jay
"Terry Olsen" <to******@hotmail.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl... Can I have an Event & Method with the same name in the same class? I want
to have a "Close" method to close a socket and a "Close" event to be
raised when the socket is closed.

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.