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

object Boxing

Take the following code:

string s = "Hello";
object a = s;
object b = s;
would (a == b) return a true value? Basically, I want to know if
boxing the same value references only one object, or if each object
creates a new reference, but with the same value. Thanks!
Nov 15 '05 #1
2 1026
Hi Maheal,

With such a small question, it's actually quicker to start a project and put that code
in it and see what happens.

When you do, don't forget that strings are reference types. You'll have to
do the same with a couple of ints and a structure to convince yourself that the
behaviour is consistent across the board.

Then you can come back and say - I found 'xxx' can someone explain. But
you might not need to do that because your experiment may have told you
enough.

Regards,
Fergus
Nov 15 '05 #2
Maheal <ma********@yahoo.com> wrote:
Take the following code:

string s = "Hello";
object a = s;
object b = s;
would (a == b) return a true value? Basically, I want to know if
boxing the same value references only one object, or if each object
creates a new reference, but with the same value. Thanks!


There's no boxing going on there - string is a reference type.

However, if you do:

int i = 10;
object a = i;
object b = i;

then the objects will indeed be different, and (a==b) is false.

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

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

Similar topics

22
by: Dr Duck | last post by:
GDay all, Something seems odd to me.... I wrote a simple C# function public void bind(ref object a, ref object b, bool atob) { if(atob) b = a; else
14
by: Matt | last post by:
I want to know if "int" is a primitive type, or an object? For example, the following two approaches yield the same result. > int t1 = int.Parse(TextBox2.Text); //method 1 > int t2 =...
10
by: Jazper Manto | last post by:
hi i want to have a method with a ref object parameter so that i can pass any object by reference and write output in it like code below. the problem is it does not work in c# like i coded it. i...
4
by: John Kandell | last post by:
Hi, I posted this in the asp.net group, but didn't get a response. Maybe someone here can help me with this... --- Would someone be able to shed some light on what is the cost of saving a...
0
by: Pat Ireland | last post by:
To use the InvokeMember for calling a method in a dynamically loaded class requires that any arguments to the method must be past in an object . However, when I try to perform a pass by reference...
14
by: James | last post by:
I am trying to a add a method to a helper class library I built that will fade out the current form. My code is this: public void fade(object currentForm) { int z = 0; for(double i=1.0; i> 0;...
161
by: Peter Olcott | last post by:
According to Troelsen in "C# and the .NET Platform" "Boxing can be formally defined as the process of explicitly converting a value type into a corresponding reference type." I think that my...
7
by: colin | last post by:
Hi, Im a bit confused about when you cast a value type to an object. I have a property grid wich stores the data and the defualt as objects. the data is limited to primitive types, structs and...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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.