Florida .NET User Groups
Florida .NET User Groups  Status: Not logged in

Hot News
Skip Navigation Links

Our Stuff
Skip Navigation Links

Community
Skip Navigation Links

Resources
Skip Navigation Links


JOBS HERE!
Active Jobs: 14

Meetings: 59
Attendance: 2104
(12 months)


C#: c# "string" versus .NET "String"
From: Wayne Erfling 9/13/2006 9:33:06 PM
I'm just getting more hands-on with asp.net / c# after leading a team since 2003.

I can't find any articles describing when the String class is used in asp.net versus when the c# "string" data type is used.

In an example in an early chapter of one book, "string" and "String" and intermingled with no explanation of what convention is being used to choose between them.

I also can't find any articles on the subject after an hour of searching.

Has Microsoft document their convention of when to use "string" versus "String" ?

I certainly don't want to write code by trying one or the other and then wait for errors so I know when to switch to the other one.

I'm an experienced IT professional, I understand case and classes, etc... All I'm trying to understand is when String and string are typically used so that I won't have to struggle with this too often.

Thanks!


From: Roy Lawson 9/15/2006 12:08:52 PM
As I recall "string" is a native type and "String" is an object in Java which provides provides additional functionality to the string type. I don't believe this to be the case in .NET because everything is an object.

At first I thought it may be the same in .NET as Java, but I just tested the two in a test C# app. They both have the same method signatures so it isn't like the String class extends the string type as it does in Java. I didn't need to create a new String object either. In short, I can't find a difference.

I'll be interested in hearing a definitive answer myself.

Best Regards,

Roy Lawson


From: Mark Rodonis 3/21/2008 6:56:29 AM
I'm sure this has been answered since 2006 when it was first asked, but just in case you still need an answer:

The Keyword string is just an alias for System.String

You can find this same "aliasing" when you use the int keyword rather than System.Int32, even though they're synonymous. Another example would be "object" and "System.Object" being mapped to each other (and char vs. System.Char).

Everything in the .NET framework is mapped to an object, even the value types.

So, in conclusion, use the lowercase version of string/object when you want the text to be in blue (in VS) or uppercase when you'd like to see it represented as a class (green).

Hope this helps,
Mark


C#: c# "string" versus .NET "String"

 

   
     
Copyright © 2001 - 2010 Florida .NET User Groups 
contact us or Call Dave Noderer: 954-418-9799
FlaDotNet is hosted by: http://www.appliedi.net/affiliates/windows-hosting.php?id=6783