C# language questions
Posted
by Water Cooler v2
on Stack Overflow
See other posts from Stack Overflow
or by Water Cooler v2
Published on 2010-05-20T23:27:04Z
Indexed on
2010/05/20
23:30 UTC
Read the original article
Hit count: 152
1) What is int
? Is it any different from the struct
System.Int32
? I understand that the former is a C# alias (typedef
or #define
equivalant) for the CLR type System.Int32
. Is this understanding correct?
2) When we say:
IComparable x = 10;
Is that like saying:
IComparable x = new System.Int32();
But we can't new
a struct, right?
or in C like syntax:
struct System.In32 *x;
x=>someThing = 10;
3) What is String
with a capitalized S? I see in Reflector that it is the sealed
String
class, which, of course, is a reference type, unlike the System.Int32
above, which is a value type.
What is string
, with an uncapitalized s, though? Is that also the C# alias for this class?
Why can I not see the alias definitions in Reflector?
4) Try to follow me down this subtle train of thought, if you please. We know that a storage location of a particular type can only access properties and members on its interface. That means:
Person p = new Customer();
p.Name = "Water Cooler v2"; // legal because as Name is defined on Person.
but
// illegal without an explicit cast even though the backing
// store is a Customer, the storage location is of type
// Person, which doesn't support the member/method being
// accessed/called.
p.GetTotalValueOfOrdersMade();
Now, with that inference, consider this scenario:
int i = 10;
// obvious System.object defines no member to
// store an integer value or any other value in.
// So, my question really is, when the integer is
// boxed, what is the *type* it is actually boxed to.
// In other words, what is the type that forms the
// backing store on the heap, for this operation?
object x = i;
© Stack Overflow or respective owner