Difference between object/Object and string/String

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 602 Views - Last Post: 27 September 2013 - 08:51 AM Rate Topic: -----

#1 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Difference between object/Object and string/String

Posted 27 September 2013 - 06:07 AM

I've noticed that you can declare a string or an object with or without capitalization. Since C# is case sensitive, it makes me wonder what the difference is, since both ways seem to work the same on the surface. I did a little research and from what I can tell there is no difference. I just wanted to verify that, and confirm which way would be considered best practice by the pros.
Is This A Good Question/Topic? 0
  • +

Replies To: Difference between object/Object and string/String

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3518
  • View blog
  • Posts: 12,012
  • Joined: 12-December 12

Re: Difference between object/Object and string/String

Posted 27 September 2013 - 06:32 AM

From the first link of a Google search:

Quote

string is an alias for System.String. So technically, there is no difference. It's like int vs. System.Int32.


The link also provided a useful list of aliases:

Quote

object: System.Object
string: System.String
bool: System.Boolean
byte: System.Byte
sbyte: System.SByte
short: System.Int16
ushort: System.UInt16
int: System.Int32
uint: System.UInt32
long: System.Int64
ulong: System.UInt64
float: System.Single
double: System.Double
decimal: System.Decimal
char: System.Char

Was This Post Helpful? 1
  • +
  • -

#3 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Re: Difference between object/Object and string/String

Posted 27 September 2013 - 06:38 AM

Thanks andrew. I did read that when I was researching, I guess I am just unsure of why there would be 2 different ways to do it. I thought maybe the compiler viewed them slightly differently under the hood somehow.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3518
  • View blog
  • Posts: 12,012
  • Joined: 12-December 12

Re: Difference between object/Object and string/String

Posted 27 September 2013 - 06:44 AM

There is no difference, but I'm sure you'd rather write string than System.String all over the place ;).

However, given that the System library is imported by default, it is not necessary in most circumstances to also qualify with System..
Was This Post Helpful? 1
  • +
  • -

#5 synlight  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 582
  • Joined: 14-September 11

Re: Difference between object/Object and string/String

Posted 27 September 2013 - 06:48 AM

Ahhhh that makes sense. Thank you!

On an unrelated note, I tried to give you +1 on my phone, and hit -1 instead. Commence heart attack, and manic pressing of the Home button. Seems to have worked before the request went through LOL. No more rep on my phone. (although I said that last time I did the same thing to someone about a year ago)
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3518
  • View blog
  • Posts: 12,012
  • Joined: 12-December 12

Re: Difference between object/Object and string/String

Posted 27 September 2013 - 06:59 AM

Hello. Seems to be okay, thank you.

No need to panic if you hit minus by mistake, it's easily done so most people will understand. (If they fail to understand then they probably deserve it anyway ;))

This post has been edited by andrewsw: 27 September 2013 - 07:01 AM

Was This Post Helpful? 0
  • +
  • -

#7 Michael26  Icon User is online

  • DIC-head, major DIC-head
  • member icon

Reputation: 359
  • View blog
  • Posts: 1,529
  • Joined: 08-April 09

Re: Difference between object/Object and string/String

Posted 27 September 2013 - 07:03 AM

I feel better when i help someone rather when i get +1, but of course i like getting +1 too :)
Was This Post Helpful? 0
  • +
  • -

#8 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2118
  • Posts: 3,244
  • Joined: 21-June 11

Re: Difference between object/Object and string/String

Posted 27 September 2013 - 07:04 AM

View Postandrewsw, on 27 September 2013 - 03:44 PM, said:

the System library is imported by default


It's not. You need to write using System; to import the System namespace.
Was This Post Helpful? 0
  • +
  • -

#9 Michael26  Icon User is online

  • DIC-head, major DIC-head
  • member icon

Reputation: 359
  • View blog
  • Posts: 1,529
  • Joined: 08-April 09

Re: Difference between object/Object and string/String

Posted 27 September 2013 - 07:06 AM

really?
The default template always imports these namespaces
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


That is from winforms and console template.
Was This Post Helpful? 0
  • +
  • -

#10 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Difference between object/Object and string/String

Posted 27 September 2013 - 07:15 AM

View Postandrewsw, on 27 September 2013 - 06:44 AM, said:

given that the System library is imported by default

I don't like the term 'imported' (but haven't found a better term) as it implies something that isn't true. It isn't imported, it just allows you to references classes in it without the fully qualified namespace.
Was This Post Helpful? 0
  • +
  • -

#11 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3518
  • View blog
  • Posts: 12,012
  • Joined: 12-December 12

Re: Difference between object/Object and string/String

Posted 27 September 2013 - 07:21 AM

'Included' isn't much better I suppose. 'Referenced'?

I suppose I should clarify. When I said 'imported by default' I meant that on starting a new Project (WinForm or Console) Visual Studio will automatically add the line:

using System;

and others to your code-files so that System classes and objects can be referred to without qualification.

This post has been edited by andrewsw: 27 September 2013 - 07:26 AM

Was This Post Helpful? 0
  • +
  • -

#12 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4498
  • View blog
  • Posts: 7,850
  • Joined: 08-June 10

Re: Difference between object/Object and string/String

Posted 27 September 2013 - 07:26 AM

"Reference" has a different meaning too. That's when you've added a reference to an assembly in your project, not when you add the using directive. "Including" is as good a word as any for me.
Was This Post Helpful? 0
  • +
  • -

#13 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3518
  • View blog
  • Posts: 12,012
  • Joined: 12-December 12

Re: Difference between object/Object and string/String

Posted 27 September 2013 - 07:29 AM

View PostCurtis Rutland, on 27 September 2013 - 02:26 PM, said:

"Reference" has a different meaning too. That's when you've added a reference to an assembly in your project, not when you add the using directive. "Including" is as good a word as any for me.

They appear in the References folder in Solution Explorer :)
Was This Post Helpful? 0
  • +
  • -

#14 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4498
  • View blog
  • Posts: 7,850
  • Joined: 08-June 10

Re: Difference between object/Object and string/String

Posted 27 September 2013 - 07:32 AM

Right. But the point I'm making is that there are two distinct things going on there. Adding the reference lets you use the constructs defined in the assembly, where as adding the using directive lets you use a shorter name for those constructs. I know you already know that, but a lot of people don't understand the difference or point.
Was This Post Helpful? 0
  • +
  • -

#15 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,469
  • Joined: 29-May 08

Re: Difference between object/Object and string/String

Posted 27 September 2013 - 07:35 AM

C# has two meaning for the Using statements. Import Namespace and automatic disposing.
using foo.bar;

using blah
{
}


In vb.net it is slightly easier to understand.
Import System.Runtime.CompilerServices

Using blah

End Using


So you're importing that namespace, so contents of that namespace can be used without stating the full namespace. Expect in situations of ubiquity where a fuller name is required to diabiquite them.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2