473,789 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

difference between reference and reference type?with example

12 New Member
difference between reference and reference type?with example
Mar 22 '08 #1
1 1087
bluefootedpig
7 New Member
difference between reference and reference type?with example
worlds of difference.

first, a reference type is anything that is contained in the heap as oppose to the stack. These values are also known as primitive vs reference. the easy way to think about it is variables such as int, bool, char are all contained on the stack. String, object, myCustomObject, any other object is contained in the heap, therefore these values are considered a reference type. A reference, is a variable, any one. They are all references. Some of them reference the stack, some reference the heap.

my guess this came up with you did an "as". Like when you do myVar as int, which wont work because you can't recast values on the stack. It is saying you want to interrupt the value at that reference as a stack type, but that doesn't make sense. You can only re-interupt that which is in memory (not on the stack). That is why you must cast (int) myVar.

Another way to think about is that a value on the stack is never null. You can't reference "null" when it points to the stack, the stack has no null address. But when pointing to memory, there is a valid null location, memory location 0. So if you try to cast something using "as", it will fail because it wants to return null if it isnt correct, and therefore you cannot have a null stack reference (int refereces to the stack).

so to recap:
referenced type is any type held in the heap as oppose to the stack.
a referenced is any variable as it "references " data.
Mar 22 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
3680
by: yufufi | last post by:
lets say we have a 'shape' class which doesn't implement IComparable interface.. compiler doesn't give you error for the lines below.. shape b= new shape(); IComparable h; h=(IComparable)b; but it complains for the following lines
5
8732
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but conceptually speaking : when do I define something as 'struct' and when as 'class' ? for example : if I want to represent a 'Time' thing, containing : - data members : hours, mins, secs
4
6506
by: ad | last post by:
I am confuse about type and class in some book about C#. What is the difference between type and class?
3
1231
by: Jon S via DotNetMonster.com | last post by:
Hi all, Can someone please give me a brief explaination how each of the following differs? long lVariable; //Variable name and type. //How do the following methods differ??? 1) (string)lVariable;
0
10408
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
10199
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
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
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
6769
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
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
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
2
3700
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.