PC Review


Reply
Thread Tools Rate Thread

Array Objects pointers, value types reference types??

 
 
plau011@hotmail.com
Guest
Posts: n/a
 
      10th Feb 2006
Hi all,
I thought I understood .Net Framework with value types and
referencetypes but apparently not.
So I have this code. Excuse me if it's not 100% correct I cut and paste
and shortened it a bit to make things clearer
So basically the purpose of this code was to have to arrays passed in
byref _BInfo
and CInfo.
Then base on another list of items that gets passed through is to fill
one or the other.
I was wanting to use a array of objects pointer to "point" to BInfo or
CInfo Array

'Dim BInfo(,) As Object 'passed in byref
'Dim CInfo(,) As Object 'passed in byref
' Dim Mycoll as collection
Dim NodetoSet(,) As Object
Dim UpperBound As Integer

For Each X in Coll Loop ' Not important
If X.UseB Then
ReDim BINFO(30, UBound(BInfo) + 1)
NodetoSet = BINFO ' What is this doing. Is it
copying data from BINFO to NodetoSet why? Shouldn't it treat as a
pointer??
Else
ReDim CInfo(30, UBound(CInfo) + 1)
NodetoSet = CInfo ' What is this doing. Is it
copying data from BINFO to NodetoSet why? Shouldn't it treat as a
pointer??
End If
UpperBound = UBound(NodetoSet, 2) - 1
'doing stuff with NodeToSet
NodeToSet(UpperBound,1) = "hello"
NodeToSet(UpperBound,1) = "goodbye" 'And so on....
Next
Thanks in advance

 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      10th Feb 2006
(E-Mail Removed) wrote:
> Hi all,
> I thought I understood .Net Framework with value types and
> referencetypes but apparently not.
> So I have this code. Excuse me if it's not 100% correct I cut and paste
> and shortened it a bit to make things clearer
> So basically the purpose of this code was to have to arrays passed in
> byref _BInfo
> and CInfo.
> Then base on another list of items that gets passed through is to fill
> one or the other.
> I was wanting to use a array of objects pointer to "point" to BInfo or
> CInfo Array
>
> 'Dim BInfo(,) As Object 'passed in byref
> 'Dim CInfo(,) As Object 'passed in byref
> ' Dim Mycoll as collection
> Dim NodetoSet(,) As Object
> Dim UpperBound As Integer
>
> For Each X in Coll Loop ' Not important
> If X.UseB Then
> ReDim BINFO(30, UBound(BInfo) + 1)
> NodetoSet = BINFO ' What is this doing. Is it
> copying data from BINFO to NodetoSet why? Shouldn't it treat as a
> pointer??
> Else
> ReDim CInfo(30, UBound(CInfo) + 1)
> NodetoSet = CInfo ' What is this doing. Is it
> copying data from BINFO to NodetoSet why? Shouldn't it treat as a
> pointer??
> End If
> UpperBound = UBound(NodetoSet, 2) - 1
> 'doing stuff with NodeToSet
> NodeToSet(UpperBound,1) = "hello"
> NodeToSet(UpperBound,1) = "goodbye" 'And so on....
> Next
> Thanks in advance
>


Ok, I can't say I fully understand what you are doing here, but I think
I see some issue that may help you.

1. 'Dim BInfo(,) As Object 'passed in byref
Objects will always be passed by reference. Only native data types are
able to be passed by value.

2. NodetoSet = BINFO
This is setting NodetoSet to the same as Binfo. They both point to the
same data object now.

Hope this helps.
Chris
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Nullable types, nulls, reference & value types question. Göran Andersson Microsoft C# .NET 0 27th May 2009 11:57 AM
Re: Nullable types, nulls, reference & value types question. Roman Wagner Microsoft C# .NET 0 27th May 2009 07:22 AM
How do you create an array of pointers to managed types? (C++/CLI) memeticvirus@gmail.com Microsoft VC .NET 11 23rd Oct 2007 01:13 PM
reference types in instantiated objects DS Microsoft C# .NET 4 14th Nov 2005 10:20 AM
ByRef parameters for objects / reference types tinman Microsoft VB .NET 3 13th Apr 2004 03:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:37 PM.