473,322 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Inheritance and Array's

Hello...Maybe I am not understanding how object arrays are created - but
this problem has bothered me for some time now - Take a quick look at the
code and then my 'problem' below:

#CODE#
Public Class CustomerInfo
Dim _billto() As BillTo

Public Overloads ReadOnly Property Billing() As BillTo()
Get
Return _billto
End Get
End Property

Public Overloads ReadOnly Property Billing(ByVal index As Integer) As
BillTo
Get
Return _billto(index)
End Get
End Property

Public Sub AddBillto(ByVal bill As BillTo)
If _billto Is Nothing Then
ReDim _billto(0)
_billto(0) = bill
Else
ReDim Preserve _billto(UBound(_billto) + 1)
_billto(UBound(_billto)) = bill
End If
End Sub
End Class
Public Class customer
Private _name As String

Public Property Name() As String
Get
Return _name
End Get
Set(ByVal Value As String)
_name = Value
End Set
End Property

Public Sub Clear()
_name = ""
End Sub
End Class

Public Class BillTo
Inherits customer

End Class

#END CODE#

This is over-simplified code of course but I just wanted it to explain this
behavior - In a form I have the following code:

Private _custinfo As New CustomerInfo

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim bleh As New BillTo
bleh.Name = "test string"
_custinfo.AddBillto(bleh)
bleh.Clear()
MsgBox(_custinfo.Billing(0).Name)
End Sub

What I don't understand is why the bleh.Clear event would also be clearing
the _custinfo.Billing(0).Name 's value....Any explanations? Workarounds?

Thanks!
Nov 22 '05 #1
6 1298
Derek <as*@me.com> wrote:

<snip>
What I don't understand is why the bleh.Clear event would also be clearing
the _custinfo.Billing(0).Name 's value....Any explanations? Workarounds?


You need to understand the difference between reference types and value
types. You're only actually creating one BillTo object - if you clear
its name, that name will be gone however you access the object, whether
it's via the reference in the bleh variable, or the reference in the
array.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2
<snip>
What I don't understand is why the bleh.Clear event would also be clearing the _custinfo.Billing(0).Name 's value....Any explanations? Workarounds?


You need to understand the difference between reference types and value
types. You're only actually creating one BillTo object - if you clear
its name, that name will be gone however you access the object, whether
it's via the reference in the bleh variable, or the reference in the
array.


Maybe I'm not understanding the difference at all; I was under the
impression that everything is created with New was all ByVal...

Is there any way I can change this around somewhat to make it all ByVal
instead of ByRef?
Sorry if I'm digressing in any way...1240am

Nov 22 '05 #3
Derek <de****@hottermail.com> wrote:
Maybe I'm not understanding the difference at all; I was under the
impression that everything is created with New was all ByVal...

Is there any way I can change this around somewhat to make it all ByVal
instead of ByRef?
Sorry if I'm digressing in any way...1240am


Passing things ByVal and ByRef is a completely separate issue from
reference types vs value types.

See http://www.pobox.com/~skeet/csharp/parameters.html - it's C# based,
but not too hard to understand. It gives a brief overview of reference
types vs value types, and then moves on to the difference between
passing things by reference and by value.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #4
>
Passing things ByVal and ByRef is a completely separate issue from
reference types vs value types.

See http://www.pobox.com/~skeet/csharp/parameters.html - it's C# based,
but not too hard to understand. It gives a brief overview of reference
types vs value types, and then moves on to the difference between
passing things by reference and by value.


Thanks a lot Jon!!! - the website was very informative and helped me
understand exactly what is going on with the code above.
Nov 22 '05 #5
Derek <as*@me.com> wrote:
See http://www.pobox.com/~skeet/csharp/parameters.html - it's C# based,
but not too hard to understand. It gives a brief overview of reference
types vs value types, and then moves on to the difference between
passing things by reference and by value.
Thanks a lot Jon!!! - the website was very informative and helped me
understand exactly what is going on with the code above.


Cool. It would be very valuable to me if in your "newly enlightened"
state you could think of anything else which would help to make the
site clearer. It's one of those issues that's absolutely key to
understanding .NET, and it's rarely treated well in books or tutorials
:(

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #6
Cool. It would be very valuable to me if in your "newly enlightened"
state you could think of anything else which would help to make the
site clearer. It's one of those issues that's absolutely key to
understanding .NET, and it's rarely treated well in books or tutorials
:(

Actually Jon, the site is very clear the way it is. The only thing (for me)
that was slightly confusing about the code I pasted before was that I was
creating multiple references in that array (which is what really threw me
off at first - how can my _billto() array be modified by this other variable
that I thought was completely out of 'its scope' so to speak).

You are absolutely right that this is one more key elements to understanding
..Net - I'm going to see what other people say about your page to see if they
can offer any suggestions.
Nov 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Peter Jakobi | last post by:
Hello, i am looking for a tool, which dumps inheritance information of c++ binaries. Does such a tool exist?? Can I retrieve interitance from the output of objdump or something else? Does...
5
by: Tony Johansson | last post by:
Hello experts! I have two class template below with names Array and CheckedArray. The class template CheckedArray is derived from the class template Array which is the base class This program...
2
by: stephane | last post by:
Hi all, What I am trying to achieve is an 'inherits' method similar to Douglas Crockford's (http://www.crockford.com/javascript/inheritance.html) but that can enable access to the superclass'...
14
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
8
by: ^MisterJingo^ | last post by:
Hi all, I have a question regarding inheritance. I'll use the following code for an example (its been stripped down to the minimum): // code start using System; class Animal {
14
by: petermichaux | last post by:
Hi, Hopefully the group doesn't mind an(other) inheritance question. Maybe the prototype inheritance style is starting to become a low dim light in my brain...probably not yet. ---- If I...
13
by: Fao | last post by:
Hello, I am having some problems with inheritance. The compiler does not not return any error messages, but when I execute the program, it only allows me to enter the number, but nothing else...
18
by: bsruth | last post by:
I tried for an hour to find some reference to concrete information on why this particular inheritance implementation is a bad idea, but couldn't. So I'm sorry if this has been answered before....
11
by: John | last post by:
Hi All, Although C# has Generics, it still does not support the generic programming paradigm. Multiple inheritance is required to support real generic programming. Here is a simple design pattern...
2
by: aitrob | last post by:
Hi, I have a problem concerning templates/inheritance. I have a code that compiles fine with g++ 4.0.1 (Apple version), but gives a lot of errors with Intel C++ 10.1 (Mac OS X). I'm not sure if...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.