Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Q: String (Capital S) vs string (small s)?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Martin Arvidsson - 08 Nov 2006 21:13 GMT
Hi

What is the difference by using String myString or string myString when
declaring a string ?

Regards
Martin
Marina Levit [MVP] - 08 Nov 2006 21:18 GMT
None.

'string' is an alias for the 'String' class. Just as 'int' is an alias for
the Int32 structure, and so on.

> Hi
>
[quoted text clipped - 3 lines]
> Regards
> Martin
gbgeek@gmail.com - 08 Nov 2006 21:23 GMT
Is there a benefit to using one over the other? I've sometimes found
myself wondering if I should declare all my int's as Int32's.

> None.
>
[quoted text clipped - 8 lines]
> > Regards
> > Martin- Hide quoted text -- Show quoted text -
Marina Levit [MVP] - 08 Nov 2006 21:37 GMT
No, I am fairly certain the compiler knows to translate one to the other.

> Is there a benefit to using one over the other? I've sometimes found
> myself wondering if I should declare all my int's as Int32's.
[quoted text clipped - 12 lines]
>> > Regards
>> > Martin- Hide quoted text -- Show quoted text -
John J. Hughes II - 08 Nov 2006 21:43 GMT
int is mapped to System.Int32 so other then typing more you won't accomplish
much :)

Regards,
John

> Is there a benefit to using one over the other? I've sometimes found
> myself wondering if I should declare all my int's as Int32's.
[quoted text clipped - 12 lines]
>> > Regards
>> > Martin- Hide quoted text -- Show quoted text -
Jon Skeet [C# MVP] - 08 Nov 2006 22:11 GMT
> Is there a benefit to using one over the other? I've sometimes found
> myself wondering if I should declare all my int's as Int32's.

I use the keyword names in my code for the sake of keyword higlighting
- but for library methods, you should use the type name (eg
Convert.ToInt32) so that it's not tailored to one particular .NET
language.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

gbgeek - 08 Nov 2006 22:28 GMT
That's sound advice. Is that the reason these aliases exist in C#? To
provide a way to refer to objects in a non-language specific way?

>  <gbg...@gmail.com> wrote:
> > Is there a benefit to using one over the other? I've sometimes found
[quoted text clipped - 6 lines]
> Jon Skeet - <s...@pobox.com>http://www.pobox.com/~skeet  Blog:http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too
Dave Sexton - 08 Nov 2006 22:28 GMT
Hi Jon,

I do the same for keyword highlighting, but I'm not clear on why I shouldn't
in library methods.  Once compiled to CIL, I don't see how it would matter.

Are you suggesting that I use Convert.ToInt32 instead of casting to (int),
even in cases where I know that an explicit cast exists?

Signature

Dave Sexton

>> Is there a benefit to using one over the other? I've sometimes found
>> myself wondering if I should declare all my int's as Int32's.
[quoted text clipped - 3 lines]
> Convert.ToInt32) so that it's not tailored to one particular .NET
> language.
Jon Skeet [C# MVP] - 08 Nov 2006 22:39 GMT
> I do the same for keyword highlighting, but I'm not clear on why I shouldn't
> in library methods.  Once compiled to CIL, I don't see how it would matter.
>
> Are you suggesting that I use Convert.ToInt32 instead of casting to (int),
> even in cases where I know that an explicit cast exists?

No, I'm suggesting that you write methods with names of ToInt32 and
ToSingle rather than ToInt and ToFloat. I wasn't talking about
implementation, just naming - sorry to confuse :(

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dave Sexton - 08 Nov 2006 22:42 GMT
Hi Jon,

Ok, that makes more sense!

Signature

Dave Sexton

>> I do the same for keyword highlighting, but I'm not clear on why I
>> shouldn't
[quoted text clipped - 6 lines]
> ToSingle rather than ToInt and ToFloat. I wasn't talking about
> implementation, just naming - sorry to confuse :(
Kevin Frey - 19 Nov 2006 23:17 GMT
Is this alias something internal to the compiler, or declared somewhere in
code?

In other words, could I use this aliasing feature for my own types?

Kevin

> None.
>
[quoted text clipped - 8 lines]
>> Regards
>> Martin
Jon Skeet [C# MVP] - 20 Nov 2006 02:51 GMT
> Is this alias something internal to the compiler, or declared somewhere in
> code?
>
> In other words, could I use this aliasing feature for my own types?

You can alias types with the "using" directive at the start of a file,
but you can't add your own "global" aliases.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.