473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

"object" or "Object" whats the difference

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
3 1471
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Randy Yates | last post by:
Having done a bit of Access Basic programming, I'm realizing that AB does seem to have (as much as I hate to admit it since I think it's a toy language) an advantage over C++. Let's say I have a...
7
by: Bennett Haselton | last post by:
Is there any way to find a string representing an object's class, which will work in Internet Explorer 6? "typeof" doesn't work -- it returns "object" for all objects: x =...
2
by: SmittyBroham | last post by:
Hello, I have a function that loops through 2 select lists and records the values of any hi-lighted options a user would have selected. It then sets 2 corresponding "hidden" form elements to the...
4
by: Rock | last post by:
I am getting the above error on If arrFields is nothing or arrFields.Count=0, I don't understand why I am getting the error: dim arrFields as new ArrayList arrFields =...
0
by: schneider | last post by:
Collection editor problems. I keep getting "Object does not match target type." I think it has something to do with the TypeConverter, because it work fine with-out it. I need the converter...
35
by: Chris | last post by:
Hi, I tried to create a class which must change the propety 'visible' of a <linktag in the masterpage into 'false' when the user is logged. But i get the error: "Object reference not set to an...
15
by: waltbrad | last post by:
Hello. I'm studying the book "C++ Primer Plus" by Stephan Prata. In chapter 6 he gives an exercise that reads from a file. The list is thus: 4 Sam Stone 2000 Freida Flass 100500 Tammy...
4
by: My Pet Programmer | last post by:
Ok guys, I'm really looking for someone to tell me how bad a hack this is, and if I'm close to where I should be with it. The basic situation is that I have a class which creates a basic...
0
by: Lukex30 | last post by:
Hi All! Does anyone have any idea why it is that when I try to get a value from my custom confighandler I get "object reference not set to instance of an object" The data is in the XML config...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.