성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
[정성태] "props[i].GetValue(props[i])" 코드에서 ...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>C#에서 string 형식이 primitive일까요?</h1> <p> 그동안 별 의심 없이 primitive 타입이라고 생각했는데 마침 책에 대한 다음의 의견이 있어서,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > 몇 가지 오류 ; <a target='tab' href='http://www.sysnet.pe.kr/3/0/3612'>http://www.sysnet.pe.kr/3/0/3612</a> </pre> <br /> 다시 정리하게 되었습니다. 질문자의 경우 "레퍼런스 타입인 string 타입은 거기서 제외됩니다."라고 하는 의견을 보내주었는데요.<br /> <br /> 그렇다면, 우선 primitive 타입의 정의를 먼저 봐야 할 것 같습니다. Wikipedia 정의가 좋겠지요? ^^ (위의 질문자가 "Primitive data type"이라는 복합어가 존재하지 않는다고 하는데... 아쉽지만 이렇게 있습니다.)<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Primitive data type ; <a target='tab' href='https://en.wikipedia.org/wiki/Primitive_data_type'>https://en.wikipedia.org/wiki/Primitive_data_type</a> </pre> <br /> <ul> <li><span style='color: blue; font-weight: bold'>a basic type is a data type provided by a programming language</span> as a basic building block. Most languages allow more complicated composite types to be recursively constructed starting from basic types.</li> <li><span style='color: blue; font-weight: bold'>a built-in type is a data type for which the programming language</span> provides built-in support.</li> </ul> <br /> 위의 2가지 정의에 따라 비춰보면, string 타입은 C#에게 있어 "primitive" 타입이 맞습니다.<br /> <br /> 그런데, 재미있는 것은 마이크로소프트의 입장입니다. 현재 MSDN에서 primitive 타입과 닷넷 언어간에 정리된 자료로 다음의 것이 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > 7.3 Primitive Types - Visual Studio 2003 Retired Technical documentation ; https://msdn.microsoft.com/en-us/library/aa711900(v=vs.71).aspx ; <a target='tab' href='https://www.microsoft.com/en-us/download/details.aspx?id=55979'>https://www.microsoft.com/en-us/download/details.aspx?id=55979</a> </pre> <br /> 명시된 것처럼 "string" 타입을 primitive로 분류하고 있지만, 아쉽게도 "Visual Studio .NET 2003 시절의 VB.NET"에 대한 것일 뿐 C#은 아닙니다. 또한, C#의 primitive 타입에 대해 "Eric Lippert"는 2010년 Q&A에서 다음과 같은 의견을 피력하고 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > In C# are the terms “Primitive” and “Literal” interchangeable? ; <a target='tab' href='http://stackoverflow.com/questions/2066035/in-c-sharp-are-the-terms-primitive-and-literal-interchangeable'>http://stackoverflow.com/questions/2066035/in-c-sharp-are-the-terms-primitive-and-literal-interchangeable</a> </pre> <br /> <div style='BACKGROUND-COLOR: #ccffcc; padding: 10px 10px 5px 10px; MARGIN: 0px 10px 10px 10px; FONT-FAMILY: Malgun Gothic, Consolas, Verdana; COLOR: #005555'> ...[생략]...<br /> <br /> The C# language specification uses the word "primitive" twice; it is never defined and completely vague as to what it could possibly mean. <br /> <br /> The C# language spec has no need to use or define the word "primitive" and therefore should not make use of this vague term. I've had a talk with Mads and we've agreed that future editions of the spec will be reworded to eliminate this usage completely.<br /> <br /> How other type systems specifications -- the reflection library, the CLI, the VES, and so on -- define the word "primitive" is of course up to them. <br /> <br /> Thanks for bringing up the question.<br /> </div><br /> <br /> 이야기대로, C# 5.0 스펙 문서에 보면 "primitive"라는 단어가 쓰인 것은 단 2번이고, 그나마도 별다른 정의를 하지 않고 쓰여진데다 어떤 타입이 속한다는 것에 관한 분류도 하지 않고 있습니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 그 외에는 C#의 primitive 타입에 대해 더 이상 어떤 명확한 것을 찾을 수 없었습니다. 이 쯤에서 한번 추측해봐야 할 것 같습니다.<br /> <br /> 일단, .NET Framework 차원에서는 string 타입이 primitive가 아닙니다. 이는 다음과 같이 테스트 해볼 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Type type = typeof(string); Console.WriteLine(type.IsPrimitive); // 출력 결과: False </pre> <br /> 하지만, "primitive 타입"이란 Framework 차원에서 결정되는 것이 아니고 "프로그래밍 언어" 수준에서 결정되는 것입니다. 만약, 이것이 Framework 차원에서 결정되는 것이라면 ".NET 호환 언어"에서는 아무리 언어 스펙이 "primitive"로 지원하고 있다 해도 결국 그것이 아닌 걸로 결정되는 것입니다.<br /> <br /> 한 예로 F#의 스펙을 보면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Primitive Types (F#) ; <a target='tab' href='https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/basic-types'>https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/basic-types</a> </pre> <br /> string을 VB.NET과 마찬가지로 Basic types(a superset of .NET primitive types)로 분류하고 있습니다. 그런데 또 재미있는 것은 bigint에 대한 취급입니다. bigint가 System.Numerics.BigInteger에 대한 단순히 약식 표기에 불과하다며 primitive가 아니라는 입장입니다.<br /> <br /> 모호한 것은 decimal에도 적용됩니다. decimal 역시 .NET Framework 차원에서는 primitive가 아닙니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Type type = typeof(decimal); Console.WriteLine(type.IsPrimitive); // 출력 결과: False </pre> <br /> 하지만, VB.NET, F#은 물론이고 C#에서 decimal이 primitive 타입이라는 것에는 이견이 없을 것입니다.<br /> <br /> 즉, 마이크로소프트 내부에서도 이처럼 다양하게 의견이 갈려 있는 것입니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 휴~~~ 결론 내리기가 쉽지 않습니다.<br /> <br /> 그래도, 일단 마이크로소프트의 입장을 우선 이해하는 것이 좋을 듯 합니다. Type.IsPrimitive로 인해 언어 상에서의 정의가 매우 애매해졌는데요. 어쨌든 Eric의 의견으로 보면 C#에서만큼은 primitive 단어를 밀고 있지는 않는 것 같습니다. (아마도 그것을 밀자니 프레임워크와의 개념 충돌로 2번 설명해야 하는 어려움이 있을 것입니다.)<br /> <br /> 실제로 C# 관련 MSDN 문서를 보면 primitive 대신 "Built-In Types"라고 명시하고 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Built-In Types Table (C# Reference) ; <a target='tab' href='https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/built-in-types'>https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/built-in-types</a> </pre> <br /> 따라서, 저는 C#에서의 string이 primitive라고 밀고 싶지만 질문자의 의견에 따라 "Built-in Type"으로 바꾸는 것이 더 나아 보입니다. ^^<br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1421
(왼쪽의 숫자를 입력해야 합니다.)