![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,126
Rep Power: 5
![]() |
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);
}
__________________
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 |
|
|
|
|
|
#12 |
|
Hobbyist Programmer
Join Date: Nov 2006
Location: 163H
Posts: 215
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#13 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
In C#, this:
x == y (x == null && y == null) || (x != null && x.equals(y)) x == y object.ReferenceEquals(x, y) |
|
|
|
|
|
#14 |
|
Hobbyist Programmer
Join Date: Nov 2006
Location: 163H
Posts: 215
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#15 |
|
Programmer
Join Date: Aug 2005
Location: null
Posts: 40
Rep Power: 0
![]() |
Thank you for the info and links guys
it was useful to post my question here. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |