By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,668 Members | 1,606 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,668 IT Pros & Developers. It's quick & easy.

"object" or "Object" whats the difference

P: n/a
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( ); }
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
"muesliflakes" <mu**********@yahoo.com.au> wrote in message
news:8d**************************@posting.google.c om...
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( ); }

Nov 15 '05 #2

P: n/a
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

--
This posting is provided "AS IS" with no warranties, and confers no rights.

"muesliflakes" <mu**********@yahoo.com.au> wrote in message
news:8d**************************@posting.google.c om...
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( ); }

Nov 15 '05 #3

P: n/a
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

On Wed, 4 Feb 2004 23:20:34 -0800, "Don Dumitru [MSFT]"
<do***@online.microsoft.com> wrote:
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


Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.