Passing Data

  • Thread starter Thread starter Jack
  • Start date Start date
J

Jack

Hi,

I have a hashtable that I need to pass around to different Business Objects.
My question is it better to pass it and make a locale hashtable variable and
set it equal to the passed hashtable or should I pass it and not worry about
it?

Thanks
 
Jack,

It doesn't really matter which you do. The reason is that if you set
the variable equal to the hashtable, then it is a reference to the instance.
If the instance is passed to other objects, then changes that they make will
be reflected in the hashtable that your business object is holding a
reference to.

You might want to consider cloning the hashtable for passing around.
Also, you might want to consider a data table as well (although you don't
have to), it's just that there is a little more type safety involved
(columns are of a certain type).

Hope this helps.
 
Thanks for the post. Since the changes each BO will make on the hashtable
needs to be reflected I will continue to pass it by ref. The reason why I
am using a hashtable instead of a datatable because I do not know the
structure of data and just add data to it at runtime. I rather use a
datatable however it seems to me that it is harder (at runtime) to add
columns and data.

Thanks

Nicholas Paldino said:
Jack,

It doesn't really matter which you do. The reason is that if you set
the variable equal to the hashtable, then it is a reference to the instance.
If the instance is passed to other objects, then changes that they make will
be reflected in the hashtable that your business object is holding a
reference to.

You might want to consider cloning the hashtable for passing around.
Also, you might want to consider a data table as well (although you don't
have to), it's just that there is a little more type safety involved
(columns are of a certain type).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jack said:
Hi,

I have a hashtable that I need to pass around to different Business Objects.
My question is it better to pass it and make a locale hashtable variable and
set it equal to the passed hashtable or should I pass it and not worry about
it?

Thanks
 
Jack,

Because a Hashtable is a reference type, you are always passing the
reference around. When you pass it to a method, the reference is passed,
and that reference is passed by reference, or by value.

Creating the structure of a datatable is easy. You just have to add
DataColumn instances to the Columns on DataTable class (it might be a little
more complex, but that is the thrust of it).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jack said:
Thanks for the post. Since the changes each BO will make on the hashtable
needs to be reflected I will continue to pass it by ref. The reason why I
am using a hashtable instead of a datatable because I do not know the
structure of data and just add data to it at runtime. I rather use a
datatable however it seems to me that it is harder (at runtime) to add
columns and data.

Thanks

message news:[email protected]...
Jack,

It doesn't really matter which you do. The reason is that if you set
the variable equal to the hashtable, then it is a reference to the instance.
If the instance is passed to other objects, then changes that they make will
be reflected in the hashtable that your business object is holding a
reference to.

You might want to consider cloning the hashtable for passing around.
Also, you might want to consider a data table as well (although you don't
have to), it's just that there is a little more type safety involved
(columns are of a certain type).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jack said:
Hi,

I have a hashtable that I need to pass around to different Business Objects.
My question is it better to pass it and make a locale hashtable
variable
and
set it equal to the passed hashtable or should I pass it and not worry about
it?

Thanks
 
Back
Top