Monday, January 19, 2009

String versus string in C#

A month ago I had a developer that I'm currently in the same project with questioning me about my use of string versus my use of String. She found it confusing that I didn't just use one of them consistently. I told her my idea, which is that I'm using String when accessing static members and string otherwise, but she still found it confusing.

I then decided to consult the IDesign C# Coding Standard, and looking there I found some inconsistency. I decided to ask them about it, and they seem to share my belief. See my mail and answer below.

From: Juval Lowy
Sent: den 19 december 2008 15:51
To: Tommy Bryntse
Subject: RE: Contacting IDesign

You should use String for the static members.

________________________________________
From: Tommy Bryntse
Sent: Friday, December 19, 2008 6:27 AM
To: sales@idesign.net
Subject: Contacting IDesign

Hello IDesign!

I noticed an inconsistency in your C# Coding Standard.

In section 1.10 it says

Always use … string NOT String.

While in section 2.52 it says

Use String.Empty instead of "":

Myself I’ve always used String for accessing static members in string, and string
otherwise, just as your example. Section 1.10 was about to make me change that to
always use string, but after seeing section 2.52 I’m confused. What should I do?

Kind regards,

Tommy
Post a Comment