From a6f20565464895774e6eded386dd838321015cfc Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 28 Jan 2020 18:44:36 +0000 Subject: [PATCH] Make string._stringLength readonly (#2001) --- src/libraries/System.Private.CoreLib/src/System/String.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/String.cs b/src/libraries/System.Private.CoreLib/src/System/String.cs index e543b79..9fb6801 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.cs @@ -29,10 +29,11 @@ namespace System // These fields map directly onto the fields in an EE StringObject. See object.h for the layout. // [NonSerialized] - private int _stringLength; + private readonly int _stringLength; - // For empty strings, this will be '\0' since - // strings are both null-terminated and length prefixed + // For empty strings, _firstChar will be '\0', since strings are both null-terminated and length-prefixed. + // The field is also read-only, however String uses .ctors that C# doesn't recognise as .ctors, + // so trying to mark the field as 'readonly' causes the compiler to complain. [NonSerialized] private char _firstChar; -- 2.7.4