473,789 Members | 2,925 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"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 1500
Yes, "object" is an alias to System.Object, just as "int"->System.Int32 ,
"string"->System.Strin g, "float"->System.Singl e, "double"->System.Doubl e,
"long"->System.Int64 , "bool"->System.Boolean , etc.

Jon
"muesliflak es" <mu**********@y ahoo.com.au> wrote in message
news:8d******** *************** ***@posting.goo gle.com...
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.

"muesliflak es" <mu**********@y ahoo.com.au> wrote in message
news:8d******** *************** ***@posting.goo gle.com...
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.m icrosoft.com> wrote:
System.Objec t 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
1466
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 table called "tblCars" that has the fields fYear (integer), fModel (string), fMake (string). When I perform a query in AB, I do something like: Dim rstCars As Recordset Dim year As Integer
7
42576
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 = window.open('http://www.yahoo.com/'); alert(typeof x); And I found this page: http://www.mozilla.org/js/language/js20-2002-04/core/expressions.html
2
3801
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 values and submits the form data to the server. I was error free until I added the following line: document.myform.submit();
4
1246
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 = CType(ViewState("arrFields"), ArrayList) --this is where I get the error: If arrFields is nothing or arrFields.Count=0 then Call GetFields ViewState("arrFields") = arrFields end if
0
1385
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 to format the designer output. Anyone know whats going on? I don't get any real errors...
35
3233
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 instance of an object" for the line 'If mpg.FindControl("lkred").Visible = True Then'. I couldn't find sofar the solution. Any help would be appreciated ... Thanks
15
3008
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 Tubbs
4
2179
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 calendar control, the only difference is I stole the navigation scheme from Vista (e.g., if you click on the year you zoom out to the months list, then out to the decade, and back in when you click a year, then a month). I ran into some trouble...
0
1226
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 file, here is the xml file and my code is afterwards. This code taken from the microsoft 70-536 .net foundation book 2d edition. Except the assembly name and xml file name is different which shouldnt make any difference. <?xml version="1.0"...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10410
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.