创建相同的方法名称,但使用接口或其他方式实现不同的参数大小? [英] Create Same Method Name but different Parameter size implement using interface or other way?
问题描述
我目前正在做一个带有几个类的项目,方法名称相同,但我可以使用接口或其他方式使用不同的参数大小实现吗?
示例:
所有类都有方法名称
GetData,Getby,Insert,Update,Delete
A类有方法GetData(),GetBy(),插入(a,b),更新(a,b,c),删除(a)
类B有方法GetData(),GetBy(ID),插入(ID,名称,值),更新(ID,名称,值),删除(ID)
C类可能有方法GetData(Name),GetBy(ID,Name,Category),Insert(ID,Name,Category,Value),Update(ID,Name,Category,value),Detele(ID)
我目前正在做一个带有几个类的项目,方法名称相同,但我可以使用接口或其他方式可以使用不同的参数大小实现吗?
如果方法是在不同的类中定义的,那么它们每个都可以包含你选择的任何参数列表。
如果方法在同一个类中被定义那么你可以有多个方法使用不同的参数列表。 请参阅:
https://www.dotnetheaven.com/article/polymorphism-in-visual-basic-.net
https://msdn.microsoft的.com / EN-US /库/ ms973896.aspx
I current doing a project with a few class, the method name is same but i wander can possible can have different Parameter size implement using interface or other way?
Example:
All the class have method Name
GetData, Getby, Insert, Update, Delete
Class A have Method GetData(), GetBy(), Insert(a,b), Update(a,b,c), Delete(a)
Class B Have Method GetData(), GetBy(ID), Insert(ID, Name, Value), Update(ID,Name, Value), Delete(ID)
Class C may Have Method GetData(Name), GetBy(ID, Name, Category), Insert(ID, Name, Category, Value), Update(ID, Name, Category, value), Detele(ID)
I current doing a project with a few class, the method name is same but i wander can possible can have different Parameter size implement using interface or other way?
If the methods are defined in different classes then they can each have whatever argument list you choose.
If the methods are defied in the same class then you can have multiple methods with different parameter lists. See:
https://www.dotnetheaven.com/article/polymorphism-in-visual-basic-.net
https://msdn.microsoft.com/en-us/library/ms973896.aspx
这篇关于创建相同的方法名称,但使用接口或其他方式实现不同的参数大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!