473,397 Members | 1,961 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,397 software developers and data experts.

Is a reference a special type in C#

hi

Is a reference a special type in C#. For example when i d

MyClass aRef

what are the classes that are available that i can use to probe aRef as a reference. My real goal is to make a serializable reference and to recreate the link during deserialization.

Thanks
Nov 16 '05 #1
6 1373
tham <an*******@discussions.microsoft.com> wrote:
Is a reference a special type in C#. For example when i do

MyClass aRef;

what are the classes that are available that i can use to probe aRef
as a reference. My real goal is to make a serializable reference and
to recreate the link during deserialization..


Really not sure what you mean here. In what way do you want to probe
aRef as a reference? You can find out what type of object aRef refers
to (if any) using aRef.GetType(), if that's the kind of thing you were
after.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Hi. It seem to me that you want to make use of unsafe code...

Alejandro Penate-Diaz.

"tham" <an*******@discussions.microsoft.com> wrote in message
news:2B**********************************@microsof t.com...
hi,

Is a reference a special type in C#. For example when i do

MyClass aRef;

what are the classes that are available that i can use to probe aRef as a reference. My real goal is to make a serializable reference and to recreate
the link during deserialization..
Thanks

Nov 16 '05 #3
Did I get you right: In "C-speech", you want to store a pointer to an object
in a file, reload it later so it points to the same object again?
That won't work in managed code because the GC will move your object around
in memory, so your "pointer" will point to the wrong location.
You could however store references to all "serialized objects" in a list,
and save the indices into that list in your file. That should be possible
using custom serilization.

Niki

"tham" <an*******@discussions.microsoft.com> wrote in
news:2B**********************************@microsof t.com...
hi,

Is a reference a special type in C#. For example when i do

MyClass aRef;

what are the classes that are available that i can use to probe aRef as a reference. My real goal is to make a serializable reference and to recreate
the link during deserialization..
Thanks

Nov 16 '05 #4

Ok lets say..

class A1{

A1 aRef

since aRef is not pointing to anything... can i still call aRef.GetType()... if not how can i tell aRef is a reference to what type??? Is there also a unique identifier to every instance of any class created. i need these infomation so i can serialize and deserial aRef to and from some format like xm

exampl

serializing aRef will generat
<Ref><type>A1</type><uuid>"some unique id"</uuid></Ref

when i deserial from this xml chunk i can then relink the aRef with the type of object (A1) and the instance (identified using the uuid) ..

another way of asking is if aRef is pointing to null. what kind of information can i find out about it...???

hope i havent made my question worse!!

many thanks for the repl
----- Jon Skeet [C# MVP] wrote: ----

tham <an*******@discussions.microsoft.com> wrote
Is a reference a special type in C#. For example when i d
MyClass aRef
what are the classes that are available that i can use to probe aRe

as a reference. My real goal is to make a serializable reference an
to recreate the link during deserialization.


Really not sure what you mean here. In what way do you want to probe
aRef as a reference? You can find out what type of object aRef refers
to (if any) using aRef.GetType(), if that's the kind of thing you were
after

--
Jon Skeet - <sk***@pobox.com
http://www.pobox.com/~skee
If replying to the group, please do not mail me to

Nov 16 '05 #5
yes very close i understand how gc move things around. therefore i will 'index' the objects using some GUID.
can i box and unbox a reference so i change it in another class ... sort of like how u can do the same for basic types?

i want to do this so that the relinking of the references is dont by my core system..

----- Niki Estner wrote: ----

Did I get you right: In "C-speech", you want to store a pointer to an objec
in a file, reload it later so it points to the same object again
That won't work in managed code because the GC will move your object aroun
in memory, so your "pointer" will point to the wrong location
You could however store references to all "serialized objects" in a list
and save the indices into that list in your file. That should be possibl
using custom serilization

Nik

"tham" <an*******@discussions.microsoft.com> wrote i
news:2B**********************************@microsof t.com..
hi
Is a reference a special type in C#. For example when i d
MyClass aRef
what are the classes that are available that i can use to probe aRef as reference. My real goal is to make a serializable reference and to recreat
the link during deserialization. Thank


Nov 16 '05 #6
tham <an*******@discussions.microsoft.com> wrote:
Ok lets say...

class A1{}

A1 aRef;

since aRef is not pointing to anything... can i still call
aRef.GetType()...
No. You'll get a NullReferenceException.
if not how can i tell aRef is a reference to what
type???
It's not - if it's not pointing to anything, it's null.
Is there also a unique identifier to every instance of any
class created. i need these infomation so i can serialize and
deserial aRef to and from some format like xml
No, but you could put one in for yourself, either in a separate list or
by including a "serial number" in each instance.
example

serializing aRef will generate
<Ref><type>A1</type><uuid>"some unique id"</uuid></Ref>

when i deserial from this xml chunk i can then relink the aRef with
the type of object (A1) and the instance (identified using the uuid)
...
I suppose it's possible...
another way of asking is if aRef is pointing to null. what kind of
information can i find out about it...???


If the value of aRef is null, there *is* no more information about it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7

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

Similar topics

3
by: klaas | last post by:
the following code gives rise to the beneath error message, only when a matrix object is instantiated as matrix<bool>, not with matrix<float>: /*returns a reference to the object at position...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
13
by: al.cpwn | last post by:
I get that these two are different int* get() { static int m; return &m; } int& get() {
8
by: Michael Safyan | last post by:
Dear members of comp.lang.c++, I am a little bit confused about the differences between constant references and values. I understand that it is faster to use a constant reference ("const T&") than...
11
by: asdf | last post by:
C++ allows a reference to a pointer, but doesn't allow a pointer to a reference, why?
8
by: Andre Azevedo | last post by:
Hi all, With the followin code: class MyClass { public int i; public MyClass(ref int I) { i = I;
22
by: Ruben | last post by:
Why would a method that is defined to return a reference such as with the operator overload of , operator, href& operator(int index){ return _array; } not cause a type mismatch compiler...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...

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.