Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 18th, 2007, 12:34 AM   #11
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,031
Rep Power: 5 lectricpharaoh will become famous soon enough
Perhaps this will clear up some of the confusion. From the horse's mouth, there is no semantic difference between, say, int and System.Int32. I usually stick to the C# alias types (int, string, etc), but when I call the type's static methods, such as TryParse(), I usually use the .NET Framework type. This is just a style preference of mine.

What has been said about boxing and reference vs value types is worth remembering. Boxing should only happen if you explicitly do it (ie, with a cast), or implicitly assign a value type to an object type (including passing a value type as a parameter declared as an object type). If you're aware of when this occurs, it shouldn't be a problem, but if it's unclear, it can catch you out. In particular, comparisons will behave quite differently; for value types, it will be a true comparison, but for reference types, it will be a comparison of the references, not the actual values. Compare the following:
bool boxedCompare(object x, object y)
{
  return (x == y);
}

bool unboxedCompare(int x, int y)
{
  return (x == y);
}
The second will work fine when you pass it ints. The first will return true if and only if you're comparing something to itself, and that something was already a reference type. Comparing a value type to itself will cause the values to be boxed, creating two new (and different) references, thus returning false. This is exactly the kind of behavior that can cause problems if you're not clear on what's happening.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Jan 18th, 2007, 5:03 AM   #12
pegasus001
Hobbyist Programmer
 
pegasus001's Avatar
 
Join Date: Nov 2006
Location: 163H
Posts: 213
Rep Power: 2 pegasus001 is on a distinguished road
I dont really know how C# does this, but in java when you compared objects you only compared their address and if they pointed to the same address than they would return true, else false. I have always taken this thing a priori in C# too. Is it correct or not???????
__________________
You never test the depth of a river with both feet.
The believer is happy. The doubter is wise.
Free speech carries with it some freedom to listen.
The next generation will always surpass the previous one. It`s one of the never ending cycles of life.
pegasus001 is offline   Reply With Quote
Old Jan 18th, 2007, 5:24 AM   #13
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
In C#, this:
x == y
Is loosely equivalent to this in Java:
(x == null && y == null) || (x != null && x.equals(y))
Going in the opposite direction, this in Java:
x == y
Is equivalent to this in C#:
object.ReferenceEquals(x, y)
Arevos is offline   Reply With Quote
Old Jan 18th, 2007, 5:34 AM   #14
pegasus001
Hobbyist Programmer
 
pegasus001's Avatar
 
Join Date: Nov 2006
Location: 163H
Posts: 213
Rep Power: 2 pegasus001 is on a distinguished road
OOOOOps:o . Sorry for being so dumb. I will remember that. Thanx.
__________________
You never test the depth of a river with both feet.
The believer is happy. The doubter is wise.
Free speech carries with it some freedom to listen.
The next generation will always surpass the previous one. It`s one of the never ending cycles of life.
pegasus001 is offline   Reply With Quote
Old Jan 18th, 2007, 6:38 AM   #15
jonyzz
Programmer
 
jonyzz's Avatar
 
Join Date: Aug 2005
Location: null
Posts: 40
Rep Power: 0 jonyzz is on a distinguished road
Thank you for the info and links guys it was useful to post my question here.
jonyzz is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I take a square root? Fall Back Son C 26 Oct 23rd, 2006 12:24 PM
HELP I dont know y this has an error PLEASEHELP C++ 9 Aug 4th, 2005 5:12 PM
C at College, advice if you please. Ramlag C 10 Apr 29th, 2005 9:53 PM
help out beginner with some errors (solved) monka Java 8 Mar 3rd, 2005 8:50 PM
Y for yes and N for no problem sobank C++ 4 Mar 1st, 2005 10:33 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:18 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC