Microsoft MVP성태의 닷넷 이야기
.NET : 25. C# "const" 키워드와 "static readonly"의 차이 [링크 복사], [링크+제목 복사],
조회: 17389
글쓴 사람
정성태 (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/200612257Display a Web Page in a Plain C Win32 Application
238정성태4/17/200612204ASP.NET 2.0 의 Provider 관련 쪽 소스 공개
237정성태4/17/200611935Microsoft Application Verifier
236정성태4/17/200613169IIS6 - IE static resource caching problem
235정성태4/13/200611834"Atlas" Control Toolkit for April CTP Released
234정성태4/13/200612190Access Visual Studio 2005 Team System From Macintosh and UNIX Systems, and from within the Eclipse IDE
233정성태4/13/200611916More Workflow Videos
232정성태4/13/200612928Microsoft Visual C++ 2005 Redistributable Package
231정성태4/13/200612434Windows Presentation Foundation Hands-On-Labs - February 2006 CTP
230정성태4/13/200612291Microsoft Management Model Designer
229정성태4/13/200613324Discovery Wizard for SharePoint
228정성태4/13/200612844TeamPlain Web Access for Team System
227정성태4/13/200612652Scrum for Team System Released
226정성태4/13/200612567Visual Studio Team Foundation Server MSSCCI Provider Version 1.0
224정성태4/13/200612060VC++ - GroupLab Component Library
223정성태4/13/200611194MSBuild Community Tasks Project releases new version
225정성태4/13/200610599    답변글 Visual Studio 2005 Web Application Projects (RC1)
222정성태4/13/200611679Visual Studio 2005 Security Features and Tools
220정성태6/8/200611551Shared Source Common Language Infrastructure 2.0 Release [1]
219정성태8/4/200611419Simple List Extensions Specification
218정성태4/13/2006120103rd party library - EZShellExtensions.Net 1.0 [1]
217정성태4/13/200611816Bug Details: GC fails to load in server mode if config file contains none ASCII characters
215정성태4/13/200611990http://www.400plusdifferences.com/
214정성태4/13/200610326Team Foundation Server, Biztalk 2006
216정성태4/13/200611771    답변글 Team Foundation Server 시험판 공개 다운로드
213정성태4/13/200611902Introduction to the MSN Messenger Activity SDK
... 31  32  33  34  35  36  37  [38]  39  40  41  42  43  44  45  ...