473,378 Members | 1,388 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,378 software developers and data experts.

What is the difference between "string" and "String" in C#?

I thought this would already be covered here, but my search turned up nothing.

In VS2005, if I use "String" to define a new variable/class, it colors it in
the Aqua color as it does other classes. But if I use "string", it colors it
in Navy blue as in C# reserved words (e.g. private, void, foreach, etc).

What is the diff?
Jun 29 '07 #1
6 4575
Ysgrifennodd Jeff:
I thought this would already be covered here, but my search turned up nothing.

In VS2005, if I use "String" to define a new variable/class, it colors it in
the Aqua color as it does other classes. But if I use "string", it colors it
in Navy blue as in C# reserved words (e.g. private, void, foreach, etc).

What is the diff?
Does this help?

http://www.thedatafarm.com/blog/Comm...b1140ad7c.aspx
Peter
Jun 29 '07 #2
On Jun 29, 3:48 pm, Jeff <J...@discussions.microsoft.comwrote:
I thought this would already be covered here, but my search turned up nothing.

In VS2005, if I use "String" to define a new variable/class, it colors it in
the Aqua color as it does other classes. But if I use "string", it colors it
in Navy blue as in C# reserved words (e.g. private, void, foreach, etc).

What is the diff?
It is all about politics. Some people think of a String as a class and
others think of it as a built-in type. We gotta please everybody.

Personally, I use String when I am using the methods like Format,
Join, IsNullorEmpty, Empty and I use string when I am assigning it to
a literal. It just looks weird to me to see a .(dot) following a navy-
blue. It doesn't really matter though.

In case you are wondering, the same is true for the other built-in
types. Int32, Boolean, Byte, Char, blah blah . . .

Jun 29 '07 #3
On Jun 29, 5:47 pm, "jehugalea...@gmail.com" <jehugalea...@gmail.com>
wrote:
On Jun 29, 3:48 pm, Jeff <J...@discussions.microsoft.comwrote:
I thought this would already be covered here, but my search turned up nothing.
In VS2005, if I use "String" to define a new variable/class, it colors it in
the Aqua color as it does other classes. But if I use "string", it colors it
in Navy blue as in C# reserved words (e.g. private, void, foreach, etc).
What is the diff?

It is all about politics. Some people think of a String as a class and
others think of it as a built-in type. We gotta please everybody.

Personally, I use String when I am using the methods like Format,
Join, IsNullorEmpty, Empty and I use string when I am assigning it to
a literal. It just looks weird to me to see a .(dot) following a navy-
blue. It doesn't really matter though.

In case you are wondering, the same is true for the other built-in
types. Int32, Boolean, Byte, Char, blah blah . . .
Whoever made that blog made a mistake. There is *no* difference in
speed. It all compiles it all to the same underlying code. The
additional names are to help people make the relationship between MSIL
and C# (C# is a flagship). Just as int in managed C++ translate to
Int32 in MSIL, same with C#.

Jun 29 '07 #4
Peter Bradley wrote:
Ysgrifennodd Jeff:
>I thought this would already be covered here, but my search turned up
nothing.

In VS2005, if I use "String" to define a new variable/class, it colors
it in the Aqua color as it does other classes. But if I use "string",
it colors it in Navy blue as in C# reserved words (e.g. private, void,
foreach, etc).

What is the diff?

Does this help?

http://www.thedatafarm.com/blog/Comm...b1140ad7c.aspx
No. It's wrong.
There is no difference in performance between int and Int32, string and
String, etc.
In Java, classes with similar names exist for boxed types - in C#
everything derives from object, and string is simply a shorthand alias
for System.String

Alun Harford
Jun 30 '07 #5
Jeff wrote:
I thought this would already be covered here, but my search turned up nothing.

In VS2005, if I use "String" to define a new variable/class, it colors it in
the Aqua color as it does other classes. But if I use "string", it colors it
in Navy blue as in C# reserved words (e.g. private, void, foreach, etc).

What is the diff?
The difference is that string is a keyword in C# and is an alias for
System.String. The String class is the System.String class, but as you
have using System; at the top of the file, you don't have to specify the
namespace.

The only difference when the code is compiled is how the type is
identified. Once the compiler has identified the type, there is no
difference at all.

The aliases and the framework classes works exactly the same, except for
some special cases. You can for example specify that an enum should use
an int as internal storage, but you can't specify System.Int32 instead.

--
Göran Andersson
_____
http://www.guffa.com
Jun 30 '07 #6
On Jun 29, 6:51 pm, "jehugalea...@gmail.com" <jehugalea...@gmail.com>
wrote:
On Jun 29, 5:47 pm, "jehugalea...@gmail.com" <jehugalea...@gmail.com>
wrote:
On Jun 29, 3:48 pm, Jeff <J...@discussions.microsoft.comwrote:
I thought this would already be covered here, but my search turned up nothing.
In VS2005, if I use "String" to define a new variable/class, it colors it in
the Aqua color as it does other classes. But if I use "string", it colors it
in Navy blue as in C# reserved words (e.g. private, void, foreach, etc).
What is the diff?
It is all about politics. Some people think of a String as a class and
others think of it as a built-in type. We gotta please everybody.
Personally, I use String when I am using the methods like Format,
Join, IsNullorEmpty, Empty and I use string when I am assigning it to
a literal. It just looks weird to me to see a .(dot) following a navy-
blue. It doesn't really matter though.
In case you are wondering, the same is true for the other built-in
types. Int32, Boolean, Byte, Char, blah blah . . .

Whoever made that blog made a mistake. There is *no* difference in
speed. It all compiles it all to the same underlying code. The
additional names are to help people make the relationship between MSIL
and C# (C# is a flagship). Just as int in managed C++ translate to
Int32 in MSIL, same with C#.
I think you missed the point in her blog. Here is the line I think
you are referring to (correct me if I'm wrong):

<quote>
Actually in VB, Integer is more work than Int32, but in C# int is
faster than Int32.
</quote>

I think the blogger is referring to how fast you can type each word.
In VB, Integer is a longer word than Int32 so you can type Int32
faster. In C# int is shorter than Int32 so you can type it faster.

So I think the blogger was not making a statement on the speed of
execution, which is, of course, the same.

This was just my impression, I could be wrong.

Chris

Jul 2 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeff Magouirk | last post by:
Dear All, I have written an update trigger that should write a message to an audit table When I try to update any field in the table I recieve the following error message - Stirng or...
32
by: Indrid Colt | last post by:
Thank's for your help ! Indrid
9
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but...
8
by: Peter Merwood | last post by:
I'm using some sample code from MSDN. The code includes the following statement: Dim content as = .Empty I'm not familiar with the use of the square brackets. Can someone please explain to...
35
by: pinkfloydhomer | last post by:
How do I check if a string contains (can be converted to) an int? I want to do one thing if I am parsing and integer, and another if not. /David
4
by: Trapulo | last post by:
I've a webservice with a string parameter. I call this webservice passing a string that is 1129 chars length. On the webservice, the received string is 1146 length (I tested sizes with...
8
by: rahana | last post by:
hello friends, i have a doubt,what is the difference between String s="Hello" and String s=new String("Hello") please help me.
1
by: mato81 | last post by:
Hi all! I am a newbie to WSDL. I have a questions which has been driving me crazy... If I would have a WSDL with a types element somewhat like below, what is the point of the third last row...
21
by: Sami | last post by:
string = "" or string = string.Empty? should is the proper way? Sami
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...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.