View Single Post
Old Jan 18th, 2007, 1:34 AM   #11
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