|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
"Type" in parameter listHi,
Is there a way for me to vary the Type of a parameter in a method in a class? Ideally I'd like to have a variable that I can use, such as: Public Sub MyMethod (ByVal mParm as mType) where mType can vary. Art "Art" <A**@discussions.microsoft.com> schrieb: \\\> Is there a way for me to vary the Type of a parameter in a method in a > class? Ideally I'd like to have a variable that I can use, such as: > > Public Sub MyMethod (ByVal mParm as mType) > > where mType can vary. Public Interaface IFoo Sub Goo() End Interface Public Class BlaFoo Implements IFoo Public Sub Goo() Implements IFoo.Goo ... End Sub End Class Public class BazFoo Implements IFoo ... End Class .. .. .. Public Sub DoSomething(ByVal f As IFoo) f.Goo() End Sub .. .. .. DoSomething(New BlaFoo()) DoSomething(New BazFoo()) /// The sample above shows how to use an interface (or a common base class) to limit the types of objects passed to the method to the parameter's type and all its subtypes. By changing the type of the method's parameter to 'Object', you change it to the most generic type. You can pass objects of any type to this parameter. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Herfried,
Thanks for this also. This one will take me a little time to try out. Art Show quoteHide quote "Herfried K. Wagner [MVP]" wrote: > "Art" <A**@discussions.microsoft.com> schrieb: > > Is there a way for me to vary the Type of a parameter in a method in a > > class? Ideally I'd like to have a variable that I can use, such as: > > > > Public Sub MyMethod (ByVal mParm as mType) > > > > where mType can vary. > > \\\ > Public Interaface IFoo > Sub Goo() > End Interface > > Public Class BlaFoo > Implements IFoo > > Public Sub Goo() Implements IFoo.Goo > ... > End Sub > End Class > > Public class BazFoo > Implements IFoo > > ... > End Class > .. > .. > .. > Public Sub DoSomething(ByVal f As IFoo) > f.Goo() > End Sub > .. > .. > .. > DoSomething(New BlaFoo()) > DoSomething(New BazFoo()) > /// > > The sample above shows how to use an interface (or a common base class) to > limit the types of objects passed to the method to the parameter's type and > all its subtypes. > > By changing the type of the method's parameter to 'Object', you change it to > the most generic type. You can pass objects of any type to this parameter. > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://classicvb.org/petition/> > > "Art" <A**@discussions.microsoft.com> schrieb: In addition to my previous reply, you may want to use 'TypeOf' to determine > Thanks for this also. This one will take me a little time to try out. the type of the object passed to the parameter: \\\ Public Sub ClearControl(ByVal Control As Control) If TypeOf Control Is TextBox Then DirectCast(Control, TextBox).Text = "" ... ElseIf TypeOf Control Is ... Then ... Else... ... ... End If End Sub /// -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Art,
Although I don't like it pass as object and get it out the method by using the typeof Cor Cor,
Yeah, I don't like it either -- that's why I was hoping for something a little better. Thanks as always! Art Show quoteHide quote "Cor Ligthert" wrote: > Art, > > Although I don't like it pass as object and get it out the method by using > the typeof > > Cor > > >
64 HI/LO DWORD extraction vb.net
Excel ADO question Using a variable to specify the name of a control Datalist/datatable sorting Formatting timespan objects how to use CurrentRowIndex for datagrid control ? SQL-question VB.NET (ASP) Can't convert Dates...help! memory stream XML and unicode problem StackTraceException on program start |
|||||||||||||||||||||||