번역/C# Notes for Professionals
32.3: 불변 참조 타입 (Immutable reference type) - string
노초코
2021. 11. 17. 22:36
Section 32.3: 불변 참조 타입 (Immutable reference type) - string
// 문자열 literal 로부터 새로운 string 을 할당한다
string s = "hello";
// 문자 배열로부터 새로운 string 을 할당한다
char[] chars = new char[] {'h', 'e', 'l', 'l', 'o'};
string s = new string(chars, 0, chars.Length);
// 문자열의 char 포인터로부터 새로운 string 을 할당한다
string s;
unsafe {
fixed(char * charPointer = "hello") {
s = new string(charPointer);
}
}
본 문서는 C# Notes for Professionals (라이센스:CC-BY-SA) 를 한글로 번역한 문서입니다. 번역상 오류가 있을 수 있으므로 정확한 내용은 원본 문서를 참고하세요.
[출처] https://books.goalkicker.com/CSharpBook/
반응형