"object" or "Object" whats the difference

  • Thread starter Thread starter muesliflakes
  • Start date Start date
M

muesliflakes

I come from Java and an Object would be the class whist object would
likly be the varible to an object.

I get the impression with C# that object is just an alias to the Base
Class Object.

Can anyone enlighten me as to any differences and by convention if I
had a method that returns an object should I use one over the other.

public object ReturnIt( ) { return new Blah( ); }
or
public Object ReturnIt( ) { return new Blah( ); }
 
Yes, "object" is an alias to System.Object, just as "int"->System.Int32,
"string"->System.String, "float"->System.Single, "double"->System.Double,
"long"->System.Int64, "bool"->System.Boolean, etc.

Jon
 
System.Object is a type surfaced by the CLR and the .Net Framework. The C#
language defines the type object, as an alias to System.Object. A similar
thing happens with System.String aka string, and some other types (which I
don't have an exhaustive list of, so I won't even make an attempt of listing
them).

If you use the name Object, that means that you must have done the statement
using System; in your program - the full type name is System.Object.

I'm fairly sure that the types are a direct alias, so using one should be
exactly the same as typing the other. But I should hedge my bets, and
suggest that maybe a super language-guru might be able to come up with an
instance where it matters?

--Don
 
The only difference between a primitive and the BCL name is on Enums.
Only primitives (byte, sbyte, short, ushort,int,uint,long,ulong) can
be used for the underlying type. The C# compiler won't allow BCL
names for enums (ex Byte, SByte, etc.)

Austin
 
Back
Top