.NET Interface Signature

Is there a reason why you need to specify variable names in interfaces. For example, look at the code below:

Public Class Class1 Public Function Test(ByVal j As Integer) End Function End Class Public Interface int1 Function Test(ByVal i As Integer) End Interface 

The integer in the class is called j, but it is called i in the interface. Why the interface will not be like this:

 Public Interface int1 Function Test(Integer) End Interface 

I understand that this is the main question. I'm just curious.

+4
source share
2 answers

At least in 2.0, if the redefinition did not match the interface signature, then you technically did not execute it http://msdn.microsoft.com/en-us/library/ms182251(v=vs.80).aspx

Currently, I am not sure about this. And why? I do not know. Do you come from another language? If I remember correctly, in the other header files of the language only the type of signature was required, but not the name.

Possible error Why should we name the parameters of the interface method? - This explains a couple of reasons that you may encounter.

+2
source

Well, one of the reasons would be if you had

 Public Interface int1 Function Test(Integer,Integer) End Interface 

As you learn when you call Test from the variable int1, what integer was ...

Basically, the compiler itself does not care about the name of the argument, we almost always do it.

After the comment.

Suppose you have two implementations of int1

Imp1.Test (A, B) and Imp2.Test (B, A)

You made

 Dim myInt1 as Int1 ... ... myInt1.Test( 

and now you are full, right? You will need to check myInt1 to see if imp1 or imp2 was, so the interface is a waste of time ...

0
source

All Articles