0

Possible Duplicate:
String vs string in C#

Yeah, I knew that both of 2 style is ok, but which one is better, and why?

Community
  • 1
  • 1
Luke
  • 1,623
  • 3
  • 24
  • 32

4 Answers4

0

In most cases, it is subject to opinion.

The less disputable facts:

  • Always use whichever your team already uses, or whichever your coding standard mandates
  • In favor of the keyword style, it doesn't require a using declaration.
  • In output from a code generator, using the fully qualified name is less of a pain to code; otherwise you have to include special handling for keyword types
  • In naming properties or methods, you should use the type name, not the keyword name. It must be translatable across .Net languages

If it is a new project, and you are in control of the coding style, use whichever tickles your fancy.

In addition to the method/property naming requirement, I've seen people say they prefer the non-keyword type name, so that it is more directly grokable across .Net languages. My opinion on this opinion is to write code to the language you are in.

Merlyn Morgan-Graham
  • 58,163
  • 16
  • 128
  • 183
0

read this thread String vs string in C# which is about String and string

Community
  • 1
  • 1
Aravind
  • 4,125
  • 1
  • 28
  • 39
0

The similar question was raised previously in StackOverFlow. And the Answer to it is given. Please refer to the following link for details:

https://stackoverflow.com/questions/215255/string-vs-string-in-c#

Community
  • 1
  • 1
Shivkant
  • 4,509
  • 1
  • 19
  • 16
0

I'll add that StyleCop ( http://stylecop.codeplex.com/ ) "prefers" the "lower case" versions.

SA1121 Readability Rules UseBuiltInTypeAlias

A violation of this rule occurs when one of the following types are used anywhere in the code: Array, Boolean, Byte, Char, Decimal, Double, Int16, Int32, Int64, Object, SByte, Single, String, UInt16, UInt32, UInt64.

A violation also occurs when any of these types are represented in the code using the full namespace for the type: System.Array, System.Boolean, System.Byte, System.Char, System.Decimal, System.Double, System.Int16, System.Int32, System.Int64, System.Object, System.SByte, System.Single, System.String, System.UInt16, System.UInt32, System.UInt64.

Rather than using the type name or the fully-qualified type name, the built-in aliases for these types should always be used: array, bool, byte, char, decimal, double, short, int, long, object, sbyte, single, string, ushort, uint, ulong.

(taken from the help file StyleCop.chm)

xanatos
  • 109,618
  • 12
  • 197
  • 280