fripper <fr*****@insightbb.com> wrote:
I have had some experience with VB .Net but I am having difficulty coming
to grips with how to set up a subroutine to accept varying classes for its
arguments. An example will help to explain. I have two arrays [call them A
and B]. The elements of array A are records whose fields are defined with a
Public Structure block (call it RecTypeA) and the elements of array B are
records defined by a different Structure block (RecTypeB). Now, each
structure has a field named Dater ... which is a date. At one point in the
program I want to sort the elements of A by the Dater field and at another
point I want to sort array B by it's Dater field. I would like to do this
with a single sort subroutine.
Make them both implement an interface which has a Dater property (not
field), and have that property in both of your other types. Then you
can just refer to the interface instead of the specific implementation.
However, this works a lot more smoothly (in terms of arrays) if your
types are classes, rather than structures.
By the way, there's no need to pass your array by reference in the
method that you've shown - arrays are reference types anyway. See
http://www.pobox.com/~skeet/csharp/parameters.html for more information
on passing by value or by reference - it's in C#, but the same applies
to VB.NET.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too