Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C# Programming Question

Name: Anonymous 2010-10-21 14:24

object a = 10;
object b = 10;
object c = "10";
object d = "10";

Console.WriteLine(a == b); // false
Console.WriteLine(c == d); // true

why does the "Console.WriteLine(a == b)" outputs "false"?

Name: Anonymous 2010-10-21 17:38

>>11
In C# everything is an object.

You can have operator== in C#.

Shut your fucking ignorant American fat face up.

Name: Anonymous 2010-10-21 17:47

>>11
IHBT In C++, not everything is an object.  A rough (and partially incorrect) estimation says that in C++, everything is either a POD (scalars, pointers, structs) or an object (class instance).  In C++ you can't have a reference type that can hold a reference to any other type (void* doesn't work).  In C#, you can cast anything to "object" and then cast it back.  Value types get boxed -- a tradeoff that makes it easier to store the value types on the stack in the first place.

In C#, "==" will work as expected when you're working with variables that are typed, just like C++.  It will compare references when you give it operands of type "object", which isn't something you can do in C++ anyway.

So really, C++ is the language where you can't cast everything to "object", both Java and C# allow this.  (This really has nothing at all to do with object-oriented programming, and everything to do with dynamic type systems, which was kind of stapled onto C++ and doesn't go "all the way down".)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List