Microsoft MVP성태의 닷넷 이야기
.NET : 25. C# "const" 키워드와 "static readonly"의 차이 [링크 복사], [링크+제목 복사],
조회: 19053
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

'const' vs 'static readonly'
; https://docs.microsoft.com/en-us/archive/blogs/davidklinems/const-vs-static-readonly

간단히 정리해 보면, "const" 키워드는 VC++의 Macro 상수 정의이고, static readonly 키워드는 값이 고정된 변수라고 보면 되겠습니다. (물론, readonly에는 생성자에서의 초기화 지원이라는 부분을 포함합니다.)

언급된 데로, 만약 여러분들이 "고정값"들만을 담고 있을 어셈블리를 별도로 정의해서 활용한다고 했을 때, 만약 그 값들이 정말 "고정된 값"들이라면 const 키워드를 써도 됩니다. 예를 들어, PI값의 정의같은 것이겠지요. 하지만, 접속될 서버 주솟값 - 실서버 배치 시에는 달라질 수 있는 - 그런 값들을 담을 계획이라면 "static readonly"로 하면 되겠습니다.

CONST vs READONLY in C#? (Explanation)
; https://dev.to/dotnetsafer/const-vs-readonly-in-c-explanation-3nh7
 









[최초 등록일: ]
[최종 수정일: 6/28/2021]


비밀번호

댓글 작성자
 




... 31  32  33  34  35  36  37  [38]  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
239정성태4/18/200613908Display a Web Page in a Plain C Win32 Application
238정성태4/17/200613799ASP.NET 2.0 의 Provider 관련 쪽 소스 공개
237정성태4/17/200613468Microsoft Application Verifier
236정성태4/17/200614777IIS6 - IE static resource caching problem
235정성태4/13/200613483"Atlas" Control Toolkit for April CTP Released
234정성태4/13/200613757Access Visual Studio 2005 Team System From Macintosh and UNIX Systems, and from within the Eclipse IDE
233정성태4/13/200613481More Workflow Videos
232정성태4/13/200614459Microsoft Visual C++ 2005 Redistributable Package
231정성태4/13/200613975Windows Presentation Foundation Hands-On-Labs - February 2006 CTP
230정성태4/13/200613874Microsoft Management Model Designer
229정성태4/13/200614847Discovery Wizard for SharePoint
228정성태4/13/200614416TeamPlain Web Access for Team System
227정성태4/13/200614256Scrum for Team System Released
226정성태4/13/200614094Visual Studio Team Foundation Server MSSCCI Provider Version 1.0
224정성태4/13/200613566VC++ - GroupLab Component Library
223정성태4/13/200612711MSBuild Community Tasks Project releases new version
225정성태4/13/200612151    답변글 Visual Studio 2005 Web Application Projects (RC1)
222정성태4/13/200613188Visual Studio 2005 Security Features and Tools
220정성태6/8/200613116Shared Source Common Language Infrastructure 2.0 Release [1]
219정성태8/4/200612953Simple List Extensions Specification
218정성태4/13/2006135903rd party library - EZShellExtensions.Net 1.0 [1]
217정성태4/13/200613302Bug Details: GC fails to load in server mode if config file contains none ASCII characters
215정성태4/13/200613452http://www.400plusdifferences.com/
214정성태4/13/200611799Team Foundation Server, Biztalk 2006
216정성태4/13/200613317    답변글 Team Foundation Server 시험판 공개 다운로드
213정성태4/13/200613454Introduction to the MSN Messenger Activity SDK
... 31  32  33  34  35  36  37  [38]  39  40  41  42  43  44  45  ...