Programming Forums
User Name Password Register
 

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

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Jan 18th, 2007, 1:34 AM   #10
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,126
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
 

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 1:24 PM
HELP I dont know y this has an error PLEASEHELP C++ 9 Aug 4th, 2005 6:12 PM
C at College, advice if you please. Ramlag C 10 Apr 29th, 2005 10:53 PM
help out beginner with some errors (solved) monka Java 8 Mar 3rd, 2005 9:50 PM
Y for yes and N for no problem sobank C++ 4 Mar 1st, 2005 11:33 PM




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

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