성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] The Windows Registry Adventure #1: ...
[정성태] systemd for Developers I ; https:/...
[정성태] 엄밀히 object 타입의 인스턴스가 다른 타입으로 형변환 가능...
[정성태] 아래의 글에서 나오는 "Windows Application Pa...
[정성태] The history of calling conventions,...
[정성태] Secure and Deploy .NET Windows Form...
[정성태] Get Started with Milvus Vector DB i...
[정성태] cyberark/PipeViewer - A tool that...
[정성태] WinForms in a 64-Bit world – our st...
[정성태] 예제에서 SELECT_SQL도 내부적으로는 SqlCommand/...
글쓰기
제목
이름
암호
전자우편
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# 9.0 - (4) 원시 크기 정수(Native ints)</h1> <p> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C# 9.0 - (1) <a target='tab' href='https://github.com/dotnet/csharplang/issues/100'>대상으로 형식화된 new 식(Target-typed new expressions)</a> ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12363'>https://www.sysnet.pe.kr/2/0/12363</a> C# 9.0 - (2) <a target='tab' href='https://github.com/dotnet/csharplang/issues/1738'>localsinit 플래그 내보내기 무시(Suppress emitting localsinit flag)</a> ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12364'>https://www.sysnet.pe.kr/2/0/12364</a> C# 9.0 - (3) <a target='tab' href='https://github.com/dotnet/csharplang/issues/111'>람다 메서드의 매개 변수 무시(Lambda discard parameters)</a> ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12365'>https://www.sysnet.pe.kr/2/0/12365</a> C# 9.0 - (4) <a target='tab' href='https://github.com/dotnet/csharplang/issues/435'>원시 크기 정수(Native ints)</a> ; https://www.sysnet.pe.kr/2/0/12366 C# 9.0 - (5) <a target='tab' href='https://github.com/dotnet/csharplang/issues/1888'>로컬 함수에 특성 지정 가능(Attributes on local functions)</a> ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12372'>https://www.sysnet.pe.kr/2/0/12372</a> C# 9.0 - (6) <a target='tab' href='https://github.com/dotnet/csharplang/issues/191'>함수 포인터(Function pointers)</a> ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12374'>https://www.sysnet.pe.kr/2/0/12374</a> C# 9.0 - (7) <a target='tab' href='https://github.com/dotnet/csharplang/issues/2850'>패턴 일치 개선 사항(Pattern matching enhancements)</a> ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12383'>https://www.sysnet.pe.kr/2/0/12383</a> C# 9.0 - (8) <a target='tab' href='https://github.com/dotnet/csharplang/issues/275'>정적 익명 함수 (static anonymous functions)</a> ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12389'>https://www.sysnet.pe.kr/2/0/12389</a> C# 9.0 - (9) <a target='tab' href='https://github.com/dotnet/csharplang/issues/39'>레코드 (Records)</a> ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12392'>https://www.sysnet.pe.kr/2/0/12392</a> C# 9.0 - (10) <a target='tab' href='https://github.com/dotnet/csharplang/issues/2460'>대상으로 형식화된 조건식(Target-typed conditional expressions)</a> ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12399'>https://www.sysnet.pe.kr/2/0/12399</a> C# 9.0 - (11) <a target='tab' href='https://github.com/dotnet/csharplang/issues/2844'>공변 반환 형식(Covariant return types)</a> ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12402'>https://www.sysnet.pe.kr/2/0/12402</a> C# 9.0 - (12) <a target='tab' href='https://github.com/dotnet/csharplang/issues/3194'>foreach 루프에 대한 GetEnumerator 확장 메서드 지원(Extension GetEnumerator)</a> ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12403'>https://www.sysnet.pe.kr/2/0/12403</a> C# 9.0 - (13) <a target='tab' href='https://github.com/dotnet/csharplang/blob/master/proposals/csharp-9.0/module-initializers.md'>모듈 이니셜라이저(Module initializers)</a> ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12404'>https://www.sysnet.pe.kr/2/0/12404</a> C# 9.0 - (14) <a target='tab' href='https://github.com/dotnet/csharplang/blob/master/proposals/csharp-9.0/extending-partial-methods.md'>부분 메서드에 대한 새로운 기능(New features for partial methods)</a> ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12405'>https://www.sysnet.pe.kr/2/0/12405</a> C# 9.0 - (15) <a target='tab' href='https://github.com/dotnet/csharplang/blob/master/proposals/csharp-9.0/top-level-statements.md'>최상위 문(Top-level statements)</a> ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12406'>https://www.sysnet.pe.kr/2/0/12406</a> C# 9.0 - (16) <a target='tab' href='https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/unconstrained-type-parameter-annotations'>제약 조건이 없는 형식 매개변수 주석(Unconstrained type parameter annotations)</a> ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12423'>https://www.sysnet.pe.kr/2/0/12423</a> </pre> <br /> <hr style='width: 50%' /><br /> <br /> 32비트 환경에서는 4바이트, 64비트 환경에서는 8바이트로 정의되는 nint, nuint 정수 타입이 새롭게 추가되었습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > using System; class Program { static void Main(string[] args) { nint x1 = 3; nuint x2 = 4; unsafe { Console.WriteLine(sizeof(nint)); Console.WriteLine(sizeof(nuint)); } } } /* 출력 결과 - 32비트의 경우 4 4 - 64비트의 경우 8 8 */ </pre> <br /> 기존에는 위와 같이 플랫폼 의존적인 타입을 갖는 네이티브 모듈들과 연동하기 위해서는 IntPtr/UIntPtr을 사용해야 했지만, 엄밀히 해당 자료형이 포인터가 아닌 경우도 있으므로 이를 위해 새로운 타입을 추가해 다양한 산술 연산자의 활용이 가능하도록 했습니다.<br /> <br /> 참고로, 비주얼 스튜디오에서 F12(Go To Definition)로 이동하면 각각 IntPtr, UIntPtr 타입으로 이동하는 것을 볼 수 있는데 실제로 내부적인 구현은 그것들에 대응합니다. 그렇긴 하지만 명시적으로 다음의 메서드들은 사용하지 못하도록 막았습니다.<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='https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/native-integers'>https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/native-integers</a> public static IntPtr MaxValue { get; } public static IntPtr MinValue { get;} public static readonly IntPtr Zero; // use 0 instead public static int Size { get; } // use sizeof() instead public static IntPtr Add(IntPtr pointer, int offset); public static IntPtr Subtract(IntPtr pointer, int offset); public int ToInt32(); public long ToInt64(); public void* ToPointer(); </pre> <br /> 따라서 nint.Zero와 같은 식의 코드는 사용할 수 없습니다. 반면, IntPtr/UIntPtr의 경우에는 명시적으로 포인터 연산이라는 특징으로 포인터끼리 더하는 연산은 제공하지 않지만,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > { IntPtr value1 = new (5); // <a target='tab' href='https://www.sysnet.pe.kr/2/0/12363'>Target-typed new</a> IntPtr value2 = new (6); IntPtr value3 = value1 + value2; // Error CS0019 Operator '+' cannot be applied to operands of type 'IntPtr' and 'IntPtr' } </pre> <br /> nint, nuint는 이러한 연산이 가능합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > { nint value1 = 5; // IntPtr처럼 new 할 필요가 없음. nint value2 = 6; nint value3 = value1 + value2; nint value4 = value1 - value2; nint value5 = value1 / value2; nint value6 = value1 * value2; nint value7 = value1 % value2; } </pre> <br /> (<a target='tab' href='https://www.sysnet.pe.kr/bbs/DownloadAttachment.aspx?fid=1637&boardid=331301885'>첨부 파일은 이 글의 예제 코드를 포함</a>합니다.)<br /> <br /> <hr style='width: 50%' /><br /> <br /> 시간 되시면 다음의 문서도! ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Native-Sized Number Types ; <a target='tab' href='https://github.com/dotnet/corefxlab/blob/master/docs/specs/nativesized.md'>https://github.com/dotnet/corefxlab/blob/master/docs/specs/nativesized.md</a> </pre> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
5088
(왼쪽의 숫자를 입력해야 합니다.)