문제

Isn't having String enough?

Just as an example,
why can String class lets you pass either char array or string array to its Split method?
while it's perfectly valid to use just string version?

  1. String.Split Method (Char[], StringSplitOptions)
  2. String.Split Method (String[], StringSplitOptions)
도움이 되었습니까?

해결책

Strings are an abstraction for arrays of characters. As such, they are technically reference types (although, unlike most references types, they are immutable) even for single-char strings. Characters, on the other hand are actually value types themselves. (MSDN 1, MSDN 2)

C# Replace Performance shows a performance implication of this, in which using character arrays is 4x faster than using string arrays.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top