am writing a class that has the same name fo开发者_JAVA技巧r events and method, but visual studion won't allow me
The event
public event Close()
the method
Public Sub Close()
End Sub
how can i do this, i don't want to use different names
thanks
The Microsoft Framework Design Guidelines specifies something along the lines of the following as best practice (these are from our internal document but derived from the former mentioned guidelines to which I will find a link):
- Do name events with a verb or a verb phrase.
- Do give event names a concept of before and after, using the present and past tense (gerunds.)
- For example, a close event that is raised before a window is closed would be called >
Closingand one that is raised after the window is closed would be calledClosed.- Do not use
BeforeorAfterprefixes or suffixes to indicate pre and post events.- Do name event handlers (delegates used as types of events) with the
EventHandlersuffix.- Do use two parameters named
senderandein event handler signatures.
- The sender parameter should be of type
Object, and theeparameter should be an instance of or inherit fromEventArgs.- Do name event argument classes with the
EventArgssuffix.- Do name event handler method with On.
- For example, a method that handles a
Closingevent should be namedOnClosing.
Update: Relevant Microsoft Design Guidelines Link.
AFAIK the .NET compiler doesn't allow this kind of overloading. Try this instead:
public event OnClose()
Public Sub Close()
    ' implementation goes here
End Sub
If the compiler allowed this then it would probably allow instance variables and delegates to have the same name, too. Imagine this (nonsensical) code:
Public Class Class1
    Public XYZ As String
    Public Event XYZ(ByVal X As XYZ)
    Public Delegate Sub XYZ()
    Public Sub XYZ()
        RaiseEvent XYZ(AddressOf XYZ)
    End Sub
End Class
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论