473,396 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
5 1310

"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
1
by: Alexey V. Dmitriev | last post by:
Hi, ALL! Try to parse my XML doc with Xerces2-J (v.2.2.0), but ErrorHandler return errors a course of this proccess. All needed features were turn on. BTW, validation under XMLSpy tool passed...
0
by: Thomas Scheffler | last post by:
Hi, I runned in trouble using XALAN for XSL-Transformation. The following snipplet show what I mean: <a href="http://blah.com/?test=test&amp;test2=test2">Test1&amp;</a> <a...
4
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated...
1
by: Perry van Kuppeveld | last post by:
Hi, I would like to submit a form through scripting, and still retrieve the click event on the server. See code below to test some stuff. Create a C# webapplication and replace the WebForm1...
7
by: comzy | last post by:
I have created an event bubbling for my pager control which is used for implementing paging in data grid. Althoug it worked very fine in .NET 1.1 it is throwing the following error after i migrated...
8
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"...
9
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT...
0
by: Slickuser | last post by:
From my PHP page: Grab all data from the database. Go through a loop to generate the HTML. Client side: From the Color drop menu list, if a user change the value. It will grab that value &...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.