943,630 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 3242
  • C# RSS
Nov 8th, 2006
0

string and String

Expand Post »
What is the difference between string and String?
If I want
string name = "Joe";
String name = "Joe";

which is the correct usage? Is there a difference?
Thanks in advance.
Similar Threads
foo
Reputation Points: 10
Solved Threads: 0
Newbie Poster
foo is offline Offline
8 posts
since Nov 2006
Nov 10th, 2006
1

Re: string and String

Click to Expand / Collapse  Quote originally posted by foo ...
What is the difference between string and String?
If I want
string name = "Joe";
String name = "Joe";

which is the correct usage? Is there a difference?
Thanks in advance.
Well, "string" is actually an object type of the System.String class. So if you omit "using System" from your program, this will not compile:

C# Syntax (Toggle Plain Text)
  1. String a = "Hello World";

Whereas this line of code would compile whether or not "using System" is in your code or not.
C# Syntax (Toggle Plain Text)
  1. string a = "Hello World";

Think of string as a "shortcut" to the System.String class whereas String is basically directly making a variable of type System.String when "using System" is in the program.

(string == System.String)

Reguards,

Tyler S. Breton
Last edited by TylerSBreton; Nov 10th, 2006 at 2:42 am.
Reputation Points: 25
Solved Threads: 3
Junior Poster in Training
TylerSBreton is offline Offline
89 posts
since Oct 2006
Nov 10th, 2006
0

Re: string and String

Thanks for replying.
So basically, I can use either or as long as I pay attention to whether using System. Using System is automatically added into new projects. I wonder, when would you not using System?
There's no advantage then of using String over string or is there?
foo
Reputation Points: 10
Solved Threads: 0
Newbie Poster
foo is offline Offline
8 posts
since Nov 2006
Nov 10th, 2006
0

Re: string and String

Click to Expand / Collapse  Quote originally posted by foo ...
Thanks for replying.
So basically, I can use either or as long as I pay attention to whether using System. Using System is automatically added into new projects. I wonder, when would you not using System?
There's no advantage then of using String over string or is there?
There is no advantage. string == System.String.

Reguards,

Tyler S. Breton
Reputation Points: 25
Solved Threads: 3
Junior Poster in Training
TylerSBreton is offline Offline
89 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Question about .Row.Add(new object[]{...,...}) Please help!
Next Thread in C# Forum Timeline: Threading Issue





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC