473,774 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can a reference be 'boxed' and 'unboxed' ala 'pointer to pointer'

HI

can i box and unbox a reference so that i can achieve a 'pointer to pointer' effect. i want to pass a reference as a parameter to a function and then have the function change what the reference is pointing to..

many thank
tham
Nov 16 '05 #1
4 1214
You don't need any boxing if you have a reference already. You just need to
make the paramater a "ref" param.

....
// the called function:
public void switchReference ( ref Hashtable collection)
{
collection = new Hashtable();
}
....
//calling it
....
Hashtable a,b;
a = new Hastable();
b = a;
//now, both a and b referr to the same Hashtable
switchReference (ref a);
//now, b still refers to the original Hashtable, a is a separate one.


"tham" <pa******@hotma il.com> wrote in message
news:0C******** *************** ***********@mic rosoft.com...
HI,

can i box and unbox a reference so that i can achieve a 'pointer to pointer' effect. i want to pass a reference as a parameter to a function and
then have the function change what the reference is pointing to...
many thanks
tham

Nov 16 '05 #2
tham <pa******@hotma il.com> wrote:
can i box and unbox a reference so that i can achieve a 'pointer to
pointer' effect. i want to pass a reference as a parameter to a
function and then have the function change what the reference is
pointing to...


No, but you can pass a reference *by* reference with the ref parameter.

See http://www.pobox.com/~skeet/csharp/parameters.html

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
ah pass by ref it is...

many thanks
Nov 16 '05 #4
Hi,
HI,

can i box and unbox a reference so that i can achieve a
'pointer to pointer' effect. i want to pass a reference as
a parameter to a function and then have the function change
what the reference is pointing to...

many thanks
tham


There's no direct representation of "pointer to pointer"
in C#, like Philip & Jon said before.

But there is indirect version object[], that can box
any type e.g. :

object[] myBox=new object[1];
myBox[0]=new MyClass();
myBox[0]=2.3;

This table ("myBox") can be parameter for any fuction, and
it should work like "pointer to pointer".

Regards

Marcin
Nov 16 '05 #5

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

Similar topics

15
1842
by: Torsten Mohr | last post by:
Hi, i'd like to pass a reference or a pointer to an object to a function. The function should then change the object and the changes should be visible in the calling function. In perl this would be something like: sub func {
15
2092
by: mark.norgate | last post by:
Hello I want to create a reference to an object, so that changes to the referenced object are reflected in the other object. Like this: object o = 123; object p = o; o = 456;
6
2177
by: ben | last post by:
i was reading this page "Optimizing Machine Learning Programs" http://hunch.net/?p=290 where in the comments at the bottom regarding the third point "Avoid Pointer-Based Representations" there is talk of unboxed arrays. having done a bit of searching i have now have a rough idea of what unboxed variables are. generally they seem to be primative variable types like int and float where the value in question is right there, not referrenced...
1
1841
by: az.anonymous | last post by:
Im starting to learn C#, and I made a simple stack class. Inside the stack class I had the following: class StackElement { object info; StackElement below; } Everything works fine cause "below" is just a reference. But, what if
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.