Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
C#で次のようなことを行うのは安全ですか、少なくとも「良い習慣」ですか?
string cnt; .... cnt = cnt.Trim();
(たとえば、C では、そのような代入に注意する必要がある場合があります。)
はい、安全です。文字列は不変であるため、多くの場合、文字列を使用することをお勧めします (元のオブジェクトは変更されず、Trim()新しいオブジェクトへの参照を返します)。
Trim()