Fix IDE0059 (unnecessary assignment)
authorStephen Toub <stoub@microsoft.com>
Fri, 16 Aug 2019 14:03:50 +0000 (10:03 -0400)
committerStephen Toub <stoub@microsoft.com>
Sat, 17 Aug 2019 11:31:50 +0000 (07:31 -0400)
Commit migrated from https://github.com/dotnet/coreclr/commit/4f12c23bc4b17bdf8cc0d82bc04342158f077bc0

43 files changed:
src/coreclr/src/System.Private.CoreLib/src/System/Exception.CoreCLR.cs
src/coreclr/src/System.Private.CoreLib/src/System/Internal.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Emit/ISymWrapperCore.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Emit/ModuleBuilder.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Emit/XXXOnTypeBuilderInstantiation.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/MdImport.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimeEventInfo.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimeParameterInfo.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToListAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationTokenTable.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToCollectionAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Windows.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/EastAsianLunisolarCalendar.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/GregorianCalendarHelper.cs
src/libraries/System.Private.CoreLib/src/System/IO/BinaryReader.cs
src/libraries/System.Private.CoreLib/src/System/IO/DisableMediaInsertionPrompt.cs
src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Win32.cs
src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Windows.cs
src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs
src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs
src/libraries/System.Private.CoreLib/src/System/Number.Dragon4.cs
src/libraries/System.Private.CoreLib/src/System/Number.Grisu3.cs
src/libraries/System.Private.CoreLib/src/System/Number.NumberToFloatingPointBits.cs
src/libraries/System.Private.CoreLib/src/System/Number.Parsing.cs
src/libraries/System.Private.CoreLib/src/System/Random.cs
src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/MemoryFailPoint.Windows.cs
src/libraries/System.Private.CoreLib/src/System/Text/DecoderExceptionFallback.cs
src/libraries/System.Private.CoreLib/src/System/Text/EncoderExceptionFallback.cs
src/libraries/System.Private.CoreLib/src/System/Text/Encoding.Internal.cs
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs
src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Win32.cs
src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs
src/libraries/System.Private.CoreLib/src/System/Type.Enum.cs
src/libraries/System.Private.CoreLib/src/System/Type.Helpers.cs

index 979f40f..dddc9b0 100644 (file)
@@ -231,7 +231,7 @@ namespace System
         {
             // Make sure that the _source field is initialized if Source is not overriden.
             // We want it to contain the original faulting point.
-            string? source = Source;
+            _ = Source;
 
             string? tmpStackTraceString = StackTrace;
 
index 9532e1c..7ddeb18 100644 (file)
@@ -316,13 +316,12 @@ namespace System
             WinRT_IEnumerable<KeyValuePair<K, V>>(null, null, null);
 
             // instantiate stubs for commonly used methods on IDictionary<K, V> and ICollection<KeyValuePair<K, V>>
-            V dummy;
             mapToDictionaryAdapter.Indexer_Get<K, V>(default);
             mapToDictionaryAdapter.Indexer_Set<K, V>(default, default);
             mapToDictionaryAdapter.ContainsKey<K, V>(default);
             mapToDictionaryAdapter.Add<K, V>(default, default);
             mapToDictionaryAdapter.Remove<K, V>(default);
-            mapToDictionaryAdapter.TryGetValue<K, V>(default, out dummy);
+            mapToDictionaryAdapter.TryGetValue<K, V>(default, out _);
             mapToCollectionAdapter.Count<K, V>();
             mapToCollectionAdapter.Add<K, V>(new KeyValuePair<K, V>(default, default));
             mapToCollectionAdapter.Clear<K, V>();
@@ -342,10 +341,9 @@ namespace System
             WinRT_IReadOnlyCollection<KeyValuePair<K, V>>(null);
 
             // instantiate stubs for commonly used methods on IReadOnlyDictionary<K, V>
-            V dummy;
             mapToDictionaryAdapter.Indexer_Get<K, V>(default);
             mapToDictionaryAdapter.ContainsKey<K, V>(default);
-            mapToDictionaryAdapter.TryGetValue<K, V>(default, out dummy);
+            mapToDictionaryAdapter.TryGetValue<K, V>(default, out _);
 
             // instantiate stubs for commonly used methods in IReadOnlyCollection<T>
             mapViewToReadOnlyCollectionAdapter.Count<K, V>();
index cd00b05..c517471 100644 (file)
@@ -16,18 +16,14 @@ namespace System.Reflection.Emit
         internal ConstructorBuilder(string name, MethodAttributes attributes, CallingConventions callingConvention,
             Type[]? parameterTypes, Type[][]? requiredCustomModifiers, Type[][]? optionalCustomModifiers, ModuleBuilder mod, TypeBuilder type)
         {
-            int sigLength;
-            byte[] sigBytes;
-            MethodToken token;
-
             m_methodBuilder = new MethodBuilder(name, attributes, callingConvention, null, null, null,
                 parameterTypes, requiredCustomModifiers, optionalCustomModifiers, mod, type, false);
 
             type.m_listMethods.Add(m_methodBuilder);
 
-            sigBytes = m_methodBuilder.GetMethodSignature().InternalGetSignature(out sigLength);
+            m_methodBuilder.GetMethodSignature().InternalGetSignature(out _);
 
-            token = m_methodBuilder.GetToken();
+            m_methodBuilder.GetToken();
         }
 
         internal ConstructorBuilder(string name, MethodAttributes attributes, CallingConventions callingConvention,
index 3e77d83..c0e6a8b 100644 (file)
@@ -170,8 +170,7 @@ namespace System.Reflection.Emit
                                                                Guid languageVendor,
                                                                Guid documentType)
             {
-                PunkSafeHandle psymUnmanagedDocumentWriter = new PunkSafeHandle();
-
+                PunkSafeHandle psymUnmanagedDocumentWriter;
                 int hr = m_vtable.DefineDocument(m_pWriter, url, ref language, ref languageVendor, ref documentType, out psymUnmanagedDocumentWriter);
                 if (hr < 0)
                 {
index b9f72a2..135fd3e 100644 (file)
@@ -533,7 +533,6 @@ namespace System.Reflection.Emit
 
         internal Type[] GetTypesNoLock()
         {
-            int size = _typeBuilderDict.Count;
             Type[] typeList = new Type[_typeBuilderDict.Count];
             int i = 0;
 
@@ -1251,7 +1250,7 @@ namespace System.Reflection.Emit
 
         internal int GetMethodTokenInternal(MethodBase method, IEnumerable<Type>? optionalParameterTypes, bool useMethodDef)
         {
-            int tk = 0;
+            int tk;
             MethodInfo? methodInfo = method as MethodInfo;
 
             if (method.IsGenericMethod)
index bc29bd6..ef5359c 100644 (file)
@@ -981,7 +981,7 @@ namespace System.Reflection.Emit
             if (TypeBuilder.IsTypeEqual(c, this))
                 return true;
 
-            Type? fromRuntimeType = null;
+            Type fromRuntimeType;
             TypeBuilder? fromTypeBuilder = c as TypeBuilder;
 
             if (fromTypeBuilder != null)
index 7acca41..5b40e3f 100644 (file)
@@ -171,7 +171,7 @@ namespace System.Reflection.Emit
         #region Private Static Members
         internal static FieldInfo GetField(FieldInfo Field, TypeBuilderInstantiation type)
         {
-            FieldInfo? m = null;
+            FieldInfo m;
 
             // This ifdef was introduced when non-generic collections were pulled from
             // silverlight. See code:Dictionary#DictionaryVersusHashtableThreadSafety
index f6fb68e..0aed9e2 100644 (file)
@@ -478,8 +478,7 @@ namespace System.Reflection
 
         public ConstArray GetMemberRefProps(int memberTokenRef)
         {
-            ConstArray signature = new ConstArray();
-
+            ConstArray signature;
             _GetMemberRefProps(m_metadataImport2, memberTokenRef, out signature);
 
             return signature;
index 68432d4..d2559dc 100644 (file)
@@ -248,7 +248,7 @@ namespace System.Reflection
 
         public override unsafe Stream? GetManifestResourceStream(string name)
         {
-            uint length = 0;
+            uint length;
             RuntimeAssembly runtimeAssembly = this;
             byte* pbInMemoryResource = GetResource(JitHelpers.GetQCallAssemblyOnStack(ref runtimeAssembly), name, out length);
 
index ad85883..9732709 100644 (file)
@@ -46,10 +46,9 @@ namespace System.Reflection
 
             scope.GetEventProps(tkEvent, out m_utf8name, out m_flags);
 
-            RuntimeMethodInfo? dummy;
             Associates.AssignAssociates(scope, tkEvent, declaredType, reflectedType,
                 out m_addMethod, out m_removeMethod, out m_raiseMethod,
-                out dummy, out dummy, out m_otherMethod, out isPrivate, out m_bindingFlags);
+                out _, out _, out m_otherMethod, out isPrivate, out m_bindingFlags);
         }
         #endregion
 
index f375e17..a2c1bba 100644 (file)
@@ -16,8 +16,7 @@ namespace System.Reflection
         {
             Debug.Assert(method is RuntimeMethodInfo || method is RuntimeConstructorInfo);
 
-            ParameterInfo? dummy;
-            return GetParameters(method, member, sig, out dummy, false);
+            return GetParameters(method, member, sig, out _, false);
         }
 
         internal static unsafe ParameterInfo GetReturnParameter(IRuntimeMethodInfo method, MemberInfo member, Signature sig)
index 0febe69..3861534 100644 (file)
@@ -41,12 +41,10 @@ namespace System.Reflection
             m_reflectedTypeCache = reflectedTypeCache;
             m_declaringType = declaredType;
 
-            ConstArray sig;
-            scope.GetPropertyProps(tkProperty, out m_utf8name, out m_flags, out sig);
+            scope.GetPropertyProps(tkProperty, out m_utf8name, out m_flags, out _);
 
-            RuntimeMethodInfo? dummy;
             Associates.AssignAssociates(scope, tkProperty, declaredType, reflectedTypeCache.GetRuntimeType(),
-                out dummy, out dummy, out dummy,
+                out _, out _, out _,
                 out m_getterMethod, out m_setterMethod, out m_otherMethod,
                 out isPrivate, out m_bindingFlags);
         }
@@ -68,14 +66,12 @@ namespace System.Reflection
             {
                 if (m_signature == null)
                 {
-                    PropertyAttributes flags;
                     ConstArray sig;
 
-                    void* name;
                     GetRuntimeModule().MetadataImport.GetPropertyProps(
-                        m_token, out name, out flags, out sig);
+                        m_token, out _, out _, out sig);
 
-                    m_signature = new Signature(sig.Signature.ToPointer(), (int)sig.Length, m_declaringType);
+                    m_signature = new Signature(sig.Signature.ToPointer(), sig.Length, m_declaringType);
                 }
 
                 return m_signature;
index 3a16752..799de6d 100644 (file)
@@ -62,8 +62,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         {
             IBindableVector _this = Unsafe.As<IBindableVector>(this);
 
-            uint index;
-            return _this.IndexOf(item, out index);
+            return _this.IndexOf(item, out _);
         }
 
         // void Clear()
index 49bdab0..2119082 100644 (file)
@@ -71,24 +71,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         }
 
 
-        public int Count
-        {
-            get
-            {
-                return lastItemIndex - firstItemIndex + 1;
-            }
-        }
-
+        public int Count => lastItemIndex - firstItemIndex + 1;
 
         // [CLSCompliant(false)]
-        public uint Size
-        {
-            get
-            {
-                return (uint)(lastItemIndex - firstItemIndex + 1);
-            }
-        }
-
+        public uint Size => (uint)(lastItemIndex - firstItemIndex + 1);
 
         public TValue Lookup(TKey key)
         {
@@ -107,27 +93,17 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         }
 
 
-        public bool HasKey(TKey key)
-        {
-            TValue value;
-            bool hasKey = TryGetValue(key, out value);
-            return hasKey;
-        }
+        public bool HasKey(TKey key) =>
+            TryGetValue(key, out _);
 
-        IEnumerator IEnumerable.GetEnumerator()
-        {
-            return ((IEnumerable<IKeyValuePair<TKey, TValue>>)this).GetEnumerator();
-        }
+        IEnumerator IEnumerable.GetEnumerator() =>
+            ((IEnumerable<IKeyValuePair<TKey, TValue>>)this).GetEnumerator();
 
-        public IIterator<IKeyValuePair<TKey, TValue>> First()
-        {
-            return new EnumeratorToIteratorAdapter<IKeyValuePair<TKey, TValue>>(GetEnumerator());
-        }
+        public IIterator<IKeyValuePair<TKey, TValue>> First() =>
+            new EnumeratorToIteratorAdapter<IKeyValuePair<TKey, TValue>>(GetEnumerator());
 
-        public IEnumerator<IKeyValuePair<TKey, TValue>> GetEnumerator()
-        {
-            return new IKeyValuePairEnumerator(items, firstItemIndex, lastItemIndex);
-        }
+        public IEnumerator<IKeyValuePair<TKey, TValue>> GetEnumerator() =>
+            new IKeyValuePairEnumerator(items, firstItemIndex, lastItemIndex);
 
         public void Split(out IMapView<TKey, TValue>? firstPartition, out IMapView<TKey, TValue>? secondPartition)
         {
@@ -206,18 +182,10 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                 }
             }
 
-            object? IEnumerator.Current
-            {
-                get
-                {
-                    return Current;
-                }
-            }
+            object? IEnumerator.Current => Current;
 
-            void IEnumerator.Reset()
-            {
+            void IEnumerator.Reset() =>
                 _current = _start - 1;
-            }
 
             public void Dispose()
             {
index edf4200..219aa8b 100644 (file)
@@ -133,7 +133,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             // take a dependency upon it.  (Simply applying the hash-value algorithm directly won't work in the
             // case of collisions, where we'll use a different token value).
 
-            uint handlerHashCode = 0;
+            uint handlerHashCode;
             Delegate[] invocationList = ((Delegate)(object)handler).GetInvocationList();
             if (invocationList.Length == 1)
             {
index 7183c46..11a5d5a 100644 (file)
@@ -113,8 +113,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             {
                 IVector<KeyValuePair<K, V>> _this_vector = Unsafe.As<IVector<KeyValuePair<K, V>>>(this);
 
-                uint index;
-                return _this_vector.IndexOf(item, out index);
+                return _this_vector.IndexOf(item, out _);
             }
         }
 
index 304f03b..9646420 100644 (file)
@@ -60,8 +60,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         {
             IVector<T> _this = Unsafe.As<IVector<T>>(this);
 
-            uint index;
-            return _this.IndexOf(item, out index);
+            return _this.IndexOf(item, out _);
         }
 
         // void CopyTo(T[] array, int arrayIndex)
index cd1868e..a695c76 100644 (file)
@@ -1062,7 +1062,7 @@ namespace System
 
                     for (int i = 0; i < tkNestedClasses.Length; i++)
                     {
-                        RuntimeType? nestedType = null;
+                        RuntimeType nestedType;
 
                         try
                         {
@@ -2089,11 +2089,8 @@ namespace System
         }
 
         // Used by the singular GetXXX APIs (Event, Field, Interface, NestedType) where prefixLookup is not supported.
-        private static void FilterHelper(BindingFlags bindingFlags, ref string name, out bool ignoreCase, out MemberListType listType)
-        {
-            bool prefixLookup;
-            FilterHelper(bindingFlags, ref name!, false, out prefixLookup, out ignoreCase, out listType);
-        }
+        private static void FilterHelper(BindingFlags bindingFlags, ref string name, out bool ignoreCase, out MemberListType listType) =>
+            FilterHelper(bindingFlags, ref name!, false, out _, out ignoreCase, out listType);
 
         // Only called by GetXXXCandidates, GetInterfaces, and GetNestedTypes when FilterHelper has set "prefixLookup" to true.
         // Most of the plural GetXXX methods allow prefix lookups while the singular GetXXX methods mostly do not.
@@ -2576,12 +2573,12 @@ namespace System
 
         private ListBuilder<Type> GetNestedTypeCandidates(string? fullname, BindingFlags bindingAttr, bool allowPrefixLookup)
         {
-            bool prefixLookup, ignoreCase;
+            bool prefixLookup;
             bindingAttr &= ~BindingFlags.Static;
             string? name, ns;
             MemberListType listType;
             SplitName(fullname, out name, out ns);
-            FilterHelper(bindingAttr, ref name, allowPrefixLookup, out prefixLookup, out ignoreCase, out listType);
+            FilterHelper(bindingAttr, ref name, allowPrefixLookup, out prefixLookup, out _, out listType);
 
             RuntimeType[] cache = Cache.GetNestedTypeList(listType, name);
 
index 273596d..ef9ae19 100644 (file)
@@ -109,22 +109,10 @@ namespace System.Globalization
         }
 
         // Get native two digit year max
-        internal static int GetTwoDigitYearMax(CalendarId calendarId)
-        {
-            if (GlobalizationMode.Invariant)
-            {
-                return Invariant.iTwoDigitYearMax;
-            }
-
-            int twoDigitYearMax = -1;
-
-            if (!CallGetCalendarInfoEx(null, calendarId, (uint)CAL_ITWODIGITYEARMAX, out twoDigitYearMax))
-            {
-                twoDigitYearMax = -1;
-            }
-
-            return twoDigitYearMax;
-        }
+        internal static int GetTwoDigitYearMax(CalendarId calendarId) =>
+            GlobalizationMode.Invariant ? Invariant.iTwoDigitYearMax :
+            CallGetCalendarInfoEx(null, calendarId, CAL_ITWODIGITYEARMAX, out int twoDigitYearMax) ? twoDigitYearMax :
+            -1;
 
         // Call native side to figure out which calendars are allowed
         internal static int GetCalendars(string localeName, bool useUserOverride, CalendarId[] calendars)
@@ -166,9 +154,8 @@ namespace System.Globalization
         {
             Debug.Assert(!GlobalizationMode.Invariant);
 
-            string data;
             // Taiwanese calendar get listed as one of the optional zh-TW calendars only when having zh-TW UI
-            return CallGetCalendarInfoEx("zh-TW", CalendarId.TAIWAN, CAL_SCALNAME, out data);
+            return CallGetCalendarInfoEx("zh-TW", CalendarId.TAIWAN, CAL_SCALNAME, out _);
         }
 
         // PAL Layer ends here
@@ -215,20 +202,19 @@ namespace System.Globalization
         ////////////////////////////////////////////////////////////////////////
         private static void CheckSpecialCalendar(ref CalendarId calendar, ref string localeName)
         {
-            string data;
 
             // Gregorian-US isn't always available in the OS, however it is the same for all locales
             switch (calendar)
             {
                 case CalendarId.GREGORIAN_US:
                     // See if this works
-                    if (!CallGetCalendarInfoEx(localeName, calendar, CAL_SCALNAME, out data))
+                    if (!CallGetCalendarInfoEx(localeName, calendar, CAL_SCALNAME, out _))
                     {
                         // Failed, set it to a locale (fa-IR) that's alway has Gregorian US available in the OS
                         localeName = "fa-IR";
                     }
                     // See if that works
-                    if (!CallGetCalendarInfoEx(localeName, calendar, CAL_SCALNAME, out data))
+                    if (!CallGetCalendarInfoEx(localeName, calendar, CAL_SCALNAME, out _))
                     {
                         // Failed again, just use en-US with the gregorian calendar
                         localeName = "en-US";
index 8008f32..14f00bf 100644 (file)
@@ -19,7 +19,7 @@ namespace System
 
         internal static DateTime ParseExact(ReadOnlySpan<char> s, ReadOnlySpan<char> format, DateTimeFormatInfo dtfi, DateTimeStyles style)
         {
-            DateTimeResult result = new DateTimeResult();       // The buffer to store the parsing result.
+            DateTimeResult result = default; // The buffer to store the parsing result.
             result.Init(s);
             if (TryParseExact(s, format, dtfi, style, ref result))
             {
@@ -33,8 +33,7 @@ namespace System
 
         internal static DateTime ParseExact(ReadOnlySpan<char> s, ReadOnlySpan<char> format, DateTimeFormatInfo dtfi, DateTimeStyles style, out TimeSpan offset)
         {
-            DateTimeResult result = new DateTimeResult();       // The buffer to store the parsing result.
-            offset = TimeSpan.Zero;
+            DateTimeResult result = default; // The buffer to store the parsing result.
             result.Init(s);
             result.flags |= ParseFlags.CaptureOffset;
             if (TryParseExact(s, format, dtfi, style, ref result))
@@ -116,7 +115,6 @@ namespace System
                                                 DateTimeFormatInfo dtfi, DateTimeStyles style, out TimeSpan offset)
         {
             DateTimeResult result = new DateTimeResult();       // The buffer to store the parsing result.
-            offset = TimeSpan.Zero;
             result.Init(s);
             result.flags |= ParseFlags.CaptureOffset;
             if (TryParseExactMultiple(s, formats, dtfi, style, ref result))
@@ -494,7 +492,7 @@ new DS[] { DS.ERROR, DS.TX_NNN,  DS.TX_NNN,  DS.TX_NNN,  DS.ERROR,   DS.ERROR,
         private static bool ParseTimeZone(ref __DTString str, ref TimeSpan result)
         {
             // The hour/minute offset for timezone.
-            int hourOffset = 0;
+            int hourOffset;
             int minuteOffset = 0;
             DTSubString sub;
 
@@ -5350,8 +5348,6 @@ new DS[] { DS.ERROR, DS.TX_NNN,  DS.TX_NNN,  DS.TX_NNN,  DS.ERROR,   DS.ERROR,
                 return;
             }
 
-            tokenType = TokenType.UnknownToken;
-
         Start:
             if (DateTimeParse.IsDigit(m_current))
             {
@@ -5449,8 +5445,7 @@ new DS[] { DS.ERROR, DS.TX_NNN,  DS.TX_NNN,  DS.TX_NNN,  DS.ERROR,   DS.ERROR,
             if (!DateTimeParse.IsDigit(m_current))
             {
                 // Not a digit.  Tokenize it.
-                int tokenValue;
-                bool found = dtfi.Tokenize(TokenType.SeparatorTokenMask, out tokenType, out tokenValue, ref this);
+                bool found = dtfi.Tokenize(TokenType.SeparatorTokenMask, out tokenType, out _, ref this);
                 if (!found)
                 {
                     tokenType = TokenType.SEP_Space;
@@ -5971,8 +5966,7 @@ new DS[] { DS.ERROR, DS.TX_NNN,  DS.TX_NNN,  DS.TX_NNN,  DS.ERROR,   DS.ERROR,
     // This will store the result of the parsing.  And it will be eventually
     // used to construct a DateTime instance.
     //
-    internal
-    ref struct DateTimeResult
+    internal ref struct DateTimeResult
     {
         internal int Year;
         internal int Month;
index 621524a..08387cf 100644 (file)
@@ -25,7 +25,8 @@ namespace System.Globalization
         {
             CheckTicksRange(time.Ticks);
 
-            TimeToLunar(time, out int year, out int month, out int day);
+
+            TimeToLunar(time, out int year, out _, out _);
             return ((year - 4) % 60) + 1;
         }
 
@@ -517,7 +518,8 @@ namespace System.Globalization
         public override int GetDayOfMonth(DateTime time)
         {
             CheckTicksRange(time.Ticks);
-            TimeToLunar(time, out int y, out int m, out int d);
+
+            TimeToLunar(time, out _, out _, out int d);
 
             return d;
         }
@@ -547,7 +549,8 @@ namespace System.Globalization
         public override int GetMonth(DateTime time)
         {
             CheckTicksRange(time.Ticks);
-            TimeToLunar(time, out int y, out int m, out int d);
+
+            TimeToLunar(time, out _, out int m, out _);
 
             return m;
         }
@@ -559,7 +562,8 @@ namespace System.Globalization
         public override int GetYear(DateTime time)
         {
             CheckTicksRange(time.Ticks);
-            TimeToLunar(time, out int y, out int m, out int d);
+
+            TimeToLunar(time, out int y, out _, out _);
 
             return GetYear(y, time);
         }
index efa47fe..70481b4 100644 (file)
@@ -516,8 +516,8 @@ namespace System.Globalization
         // Returns the number of months in the specified year and era.
         public int GetMonthsInYear(int year, int era)
         {
-            year = GetGregorianYear(year, era);
-            return (12);
+            GetGregorianYear(year, era);
+            return 12;
         }
 
         // Returns the year part of the specified DateTime. The returned value is an
@@ -592,8 +592,8 @@ namespace System.Globalization
         //
         public int GetLeapMonth(int year, int era)
         {
-            year = GetGregorianYear(year, era);
-            return (0);
+            GetGregorianYear(year, era);
+            return 0;
         }
 
         // Checks whether a given month in the specified era is a leap month. This method returns true if
index e684940..9412fc7 100644 (file)
@@ -558,11 +558,9 @@ namespace System.IO
                 ThrowIfDisposed();
 
                 int bytesRead = 0;
-                int n = 0;
-
                 do
                 {
-                    n = _stream.Read(_buffer, bytesRead, numBytes - bytesRead);
+                    int n = _stream.Read(_buffer, bytesRead, numBytes - bytesRead);
                     if (n == 0)
                     {
                         throw Error.GetEndOfFile();
index a3a2d29..c984bf0 100644 (file)
@@ -34,9 +34,8 @@ namespace System.IO
 
         public void Dispose()
         {
-            uint ignore;
             if (_disableSuccess)
-                Interop.Kernel32.SetThreadErrorMode(_oldMode, out ignore);
+                Interop.Kernel32.SetThreadErrorMode(_oldMode, out _);
         }
     }
 }
index 1f4f7fd..310d5d2 100644 (file)
@@ -58,9 +58,10 @@ namespace System.IO
 
             uint fileMode;
 
+
             int status = Interop.NtDll.NtQueryInformationFile(
                 FileHandle: fileHandle,
-                IoStatusBlock: out Interop.NtDll.IO_STATUS_BLOCK ioStatus,
+                IoStatusBlock: out _,
                 FileInformation: &fileMode,
                 Length: sizeof(uint),
                 FileInformationClass: Interop.NtDll.FileModeInformation);
index 2f6c636..c89a1d6 100644 (file)
@@ -202,16 +202,18 @@ namespace System.IO
 
         private unsafe long GetLengthInternal()
         {
-            Interop.Kernel32.FILE_STANDARD_INFO info = new Interop.Kernel32.FILE_STANDARD_INFO();
+            Interop.Kernel32.FILE_STANDARD_INFO info;
 
             if (!Interop.Kernel32.GetFileInformationByHandleEx(_fileHandle, Interop.Kernel32.FILE_INFO_BY_HANDLE_CLASS.FileStandardInfo, out info, (uint)sizeof(Interop.Kernel32.FILE_STANDARD_INFO)))
                 throw Win32Marshal.GetExceptionForLastWin32Error(_path);
             long len = info.EndOfFile;
+
             // If we're writing near the end of the file, we must include our
             // internal buffer in our Length calculation.  Don't flush because
             // we use the length of the file in our async write method.
             if (_writePos > 0 && _filePosition + _writePos > len)
                 len = _writePos + _filePosition;
+
             return len;
         }
 
index 16bd3b4..05c7071 100644 (file)
@@ -148,7 +148,7 @@ namespace System.IO
 
         private static void GetTempPath(ref ValueStringBuilder builder)
         {
-            uint result = 0;
+            uint result;
             while ((result = Interop.Kernel32.GetTempPathW(builder.Capacity, ref builder.GetPinnableReference())) > builder.Capacity)
             {
                 // Reported size is greater than the buffer size. Increase the capacity.
index 83618cf..843749a 100644 (file)
@@ -77,7 +77,7 @@ namespace System.IO
             // it doesn't root extended paths correctly. We don't currently resolve extended paths, so we'll just assert here.
             Debug.Assert(PathInternal.IsPartiallyQualified(path) || !PathInternal.IsExtended(path));
 
-            uint result = 0;
+            uint result;
             while ((result = Interop.Kernel32.GetFullPathNameW(ref MemoryMarshal.GetReference(path), (uint)builder.Capacity, ref builder.GetPinnableReference(), IntPtr.Zero)) > builder.Capacity)
             {
                 // Reported size is greater than the buffer size. Increase the capacity.
index bd75e8c..fa10ce4 100644 (file)
@@ -21,7 +21,7 @@ namespace System
 
             ulong mantissa = ExtractFractionAndBiasedExponent(value, out int exponent);
 
-            uint mantissaHighBitIdx = 0;
+            uint mantissaHighBitIdx;
             bool hasUnequalMargins = false;
 
             if ((mantissa >> DiyFp.DoubleImplicitBitIndex) != 0)
@@ -51,7 +51,7 @@ namespace System
 
             uint mantissa = ExtractFractionAndBiasedExponent(value, out int exponent);
 
-            uint mantissaHighBitIdx = 0;
+            uint mantissaHighBitIdx;
             bool hasUnequalMargins = false;
 
             if ((mantissa >> DiyFp.SingleImplicitBitIndex) != 0)
index 83f5b09..6948df7 100644 (file)
@@ -329,9 +329,9 @@ namespace System
                 Debug.Assert(v > 0);
                 Debug.Assert(double.IsFinite(v));
 
-                int length = 0;
-                int decimalExponent = 0;
-                bool result = false;
+                int length;
+                int decimalExponent;
+                bool result;
 
                 if (requestedDigits == -1)
                 {
@@ -363,9 +363,9 @@ namespace System
                 Debug.Assert(v > 0);
                 Debug.Assert(float.IsFinite(v));
 
-                int length = 0;
-                int decimalExponent = 0;
-                bool result = false;
+                int length;
+                int decimalExponent;
+                bool result;
 
                 if (requestedDigits == -1)
                 {
index 54f081d..7d0bdee 100644 (file)
@@ -258,7 +258,7 @@ namespace System
             uint middleBlockIndex = topBlockIndex - 1;
             uint bottomBlockIndex = middleBlockIndex - 1;
 
-            ulong mantissa = 0;
+            ulong mantissa;
             int exponent = baseExponent + ((int)(bottomBlockIndex) * 32);
             bool hasZeroTail = !hasNonZeroFractionalPart;
 
index 788cdab..7be59ee 100644 (file)
@@ -1115,7 +1115,6 @@ namespace System
 
             int index = 0;
             int num = value[0];
-            uint numValue;
 
             // Skip past any whitespace at the beginning.
             if ((styles & NumberStyles.AllowLeadingWhite) != 0 && IsWhite(num))
@@ -1158,6 +1157,8 @@ namespace System
                     if ((uint)index >= (uint)value.Length)
                         goto DoneAtEnd;
                     num = value[index];
+
+                    uint numValue;
                     if ((uint)num >= (uint)charToHexLookup.Length || (numValue = charToHexLookup[num]) == 0xFF)
                         goto HasTrailingChars;
                     index++;
@@ -1168,7 +1169,7 @@ namespace System
                 if ((uint)index >= (uint)value.Length)
                     goto DoneAtEnd;
                 num = value[index];
-                if ((uint)num >= (uint)charToHexLookup.Length || (numValue = charToHexLookup[num]) == 0xFF)
+                if ((uint)num >= (uint)charToHexLookup.Length || charToHexLookup[num] == 0xFF)
                     goto HasTrailingChars;
 
                 // At this point, we're either overflowing or hitting a formatting error.
@@ -1443,7 +1444,6 @@ namespace System
 
             int index = 0;
             int num = value[0];
-            uint numValue;
 
             // Skip past any whitespace at the beginning.
             if ((styles & NumberStyles.AllowLeadingWhite) != 0 && IsWhite(num))
@@ -1486,6 +1486,8 @@ namespace System
                     if ((uint)index >= (uint)value.Length)
                         goto DoneAtEnd;
                     num = value[index];
+
+                    uint numValue;
                     if ((uint)num >= (uint)charToHexLookup.Length || (numValue = charToHexLookup[num]) == 0xFF)
                         goto HasTrailingChars;
                     index++;
@@ -1496,7 +1498,7 @@ namespace System
                 if ((uint)index >= (uint)value.Length)
                     goto DoneAtEnd;
                 num = value[index];
-                if ((uint)num >= (uint)charToHexLookup.Length || (numValue = charToHexLookup[num]) == 0xFF)
+                if ((uint)num >= (uint)charToHexLookup.Length || charToHexLookup[num] == 0xFF)
                     goto HasTrailingChars;
 
                 // At this point, we're either overflowing or hitting a formatting error.
index 2d5ddb0..df7d317 100644 (file)
@@ -72,7 +72,6 @@ namespace System
             }
             _inext = 0;
             _inextp = 21;
-            Seed = 1;
         }
 
         //
index f5caa42..2668502 100644 (file)
@@ -496,8 +496,7 @@ namespace System.Resources
         {
             if (_version == 1)
                 return LoadObjectV1(pos);
-            ResourceTypeCode typeCode;
-            return LoadObjectV2(pos, out typeCode);
+            return LoadObjectV2(pos, out _);
         }
 
         internal object? LoadObject(int pos, out ResourceTypeCode typeCode)
index 8a9cab5..5d5c707 100644 (file)
@@ -11,8 +11,7 @@ namespace System.Runtime
     {
         private static ulong GetTopOfMemory()
         {
-            Interop.Kernel32.SYSTEM_INFO info = new Interop.Kernel32.SYSTEM_INFO();
-            Interop.Kernel32.GetSystemInfo(out info);
+            Interop.Kernel32.GetSystemInfo(out Interop.Kernel32.SYSTEM_INFO info);
             return (ulong)info.lpMaximumApplicationAddress;
         }
 
index a1cce71..21dd1ac 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
-using System;
 using System.Diagnostics.CodeAnalysis;
 using System.Globalization;
 using System.Runtime.Serialization;
@@ -11,38 +10,16 @@ namespace System.Text
 {
     public sealed class DecoderExceptionFallback : DecoderFallback
     {
-        // Construction
-        public DecoderExceptionFallback()
-        {
-        }
-
-        public override DecoderFallbackBuffer CreateFallbackBuffer()
-        {
-            return new DecoderExceptionFallbackBuffer();
-        }
+        public override DecoderFallbackBuffer CreateFallbackBuffer() =>
+            new DecoderExceptionFallbackBuffer();
 
         // Maximum number of characters that this instance of this fallback could return
-        public override int MaxCharCount
-        {
-            get
-            {
-                return 0;
-            }
-        }
+        public override int MaxCharCount => 0;
 
-        public override bool Equals(object? value)
-        {
-            if (value is DecoderExceptionFallback that)
-            {
-                return (true);
-            }
-            return (false);
-        }
+        public override bool Equals(object? value) =>
+            value is DecoderExceptionFallback;
 
-        public override int GetHashCode()
-        {
-            return 879;
-        }
+        public override int GetHashCode() => 879;
     }
 
 
@@ -54,25 +31,13 @@ namespace System.Text
             return true;
         }
 
-        public override char GetNextChar()
-        {
-            return (char)0;
-        }
+        public override char GetNextChar() => (char)0;
 
-        public override bool MovePrevious()
-        {
-            // Exception fallback doesn't have anywhere to back up to.
-            return false;
-        }
+        // Exception fallback doesn't have anywhere to back up to.
+        public override bool MovePrevious() => false;
 
         // Exceptions are always empty
-        public override int Remaining
-        {
-            get
-            {
-                return 0;
-            }
-        }
+        public override int Remaining => 0;
 
         [DoesNotReturn]
         private void Throw(byte[] bytesUnknown, int index)
@@ -139,20 +104,8 @@ namespace System.Text
         {
         }
 
-        public byte[]? BytesUnknown
-        {
-            get
-            {
-                return _bytesUnknown;
-            }
-        }
+        public byte[]? BytesUnknown => _bytesUnknown;
 
-        public int Index
-        {
-            get
-            {
-                return _index;
-            }
-        }
+        public int Index => _index;
     }
 }
index 3df6acc..665e4d8 100644 (file)
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
-using System;
 using System.Runtime.Serialization;
 
 namespace System.Text
@@ -14,33 +13,16 @@ namespace System.Text
         {
         }
 
-        public override EncoderFallbackBuffer CreateFallbackBuffer()
-        {
-            return new EncoderExceptionFallbackBuffer();
-        }
+        public override EncoderFallbackBuffer CreateFallbackBuffer() =>
+            new EncoderExceptionFallbackBuffer();
 
         // Maximum number of characters that this instance of this fallback could return
-        public override int MaxCharCount
-        {
-            get
-            {
-                return 0;
-            }
-        }
+        public override int MaxCharCount => 0;
 
-        public override bool Equals(object? value)
-        {
-            if (value is EncoderExceptionFallback that)
-            {
-                return true;
-            }
-            return false;
-        }
+        public override bool Equals(object? value) =>
+            value is EncoderExceptionFallback;
 
-        public override int GetHashCode()
-        {
-            return 654;
-        }
+        public override int GetHashCode() => 654;
     }
 
 
@@ -74,25 +56,13 @@ namespace System.Text
                 SR.Format(SR.Argument_InvalidCodePageConversionIndex, iTemp, index), charUnknownHigh, charUnknownLow, index);
         }
 
-        public override char GetNextChar()
-        {
-            return (char)0;
-        }
+        public override char GetNextChar() => (char)0;
 
-        public override bool MovePrevious()
-        {
-            // Exception fallback doesn't have anywhere to back up to.
-            return false;
-        }
+        // Exception fallback doesn't have anywhere to back up to.
+        public override bool MovePrevious() => false;
 
         // Exceptions are always empty
-        public override int Remaining
-        {
-            get
-            {
-                return 0;
-            }
-        }
+        public override int Remaining => 0;
     }
 
     [Serializable]
@@ -153,42 +123,15 @@ namespace System.Text
         {
         }
 
-        public char CharUnknown
-        {
-            get
-            {
-                return _charUnknown;
-            }
-        }
+        public char CharUnknown => _charUnknown;
 
-        public char CharUnknownHigh
-        {
-            get
-            {
-                return _charUnknownHigh;
-            }
-        }
+        public char CharUnknownHigh => _charUnknownHigh;
 
-        public char CharUnknownLow
-        {
-            get
-            {
-                return _charUnknownLow;
-            }
-        }
+        public char CharUnknownLow => _charUnknownLow;
 
-        public int Index
-        {
-            get
-            {
-                return _index;
-            }
-        }
+        public int Index => _index;
 
         // Return true if the unknown character is a surrogate pair.
-        public bool IsUnknownSurrogate()
-        {
-            return _charUnknownHigh != '\0';
-        }
+        public bool IsUnknownSurrogate() => _charUnknownHigh != '\0';
     }
 }
index e57ed58..83d8c56 100644 (file)
@@ -850,7 +850,7 @@ namespace System.Text
 
             ReadOnlySpan<byte> bytes = new ReadOnlySpan<byte>(pOriginalBytes, originalByteCount).Slice(bytesConsumedSoFar);
 
-            int bytesConsumedJustNow = 0;
+            int bytesConsumedJustNow;
             int totalCharCount = 0;
 
             if (decoder.HasLeftoverData)
@@ -1126,8 +1126,8 @@ namespace System.Text
             ReadOnlySpan<byte> bytes = new ReadOnlySpan<byte>(pOriginalBytes, originalByteCount).Slice(bytesConsumedSoFar);
             Span<char> chars = new Span<char>(pOriginalChars, originalCharCount).Slice(charsWrittenSoFar);
 
-            int bytesConsumedJustNow = 0;
-            int charsWrittenJustNow = 0;
+            int bytesConsumedJustNow;
+            int charsWrittenJustNow;
 
             if (decoder.HasLeftoverData)
             {
index 765c7da..8656773 100644 (file)
@@ -26,7 +26,7 @@ namespace System.Threading.Tasks
         /// </summary>
         internal ThreadPoolTaskScheduler()
         {
-            int id = base.Id; // force ID creation of the default scheduler
+            _ = base.Id; // force ID creation of the default scheduler
         }
 
         // static delegate for threads allocated to handle LongRunning tasks.
index 2bfd983..f8c658b 100644 (file)
@@ -243,8 +243,8 @@ namespace System
             //
             // Try using the "kernel32!GetDynamicTimeZoneInformation" API to get the "id"
             //
-            var dynamicTimeZoneInformation = new TIME_DYNAMIC_ZONE_INFORMATION();
 
+            TIME_DYNAMIC_ZONE_INFORMATION dynamicTimeZoneInformation;
             // call kernel32!GetDynamicTimeZoneInformation...
             uint result = Interop.Kernel32.GetDynamicTimeZoneInformation(out dynamicTimeZoneInformation);
             if (result == Interop.Kernel32.TIME_ZONE_ID_INVALID)
@@ -371,23 +371,22 @@ namespace System
         // DateTime.Now fast path that avoids allocating an historically accurate TimeZoneInfo.Local and just creates a 1-year (current year) accurate time zone
         internal static TimeSpan GetDateTimeNowUtcOffsetFromUtc(DateTime time, out bool isAmbiguousLocalDst)
         {
-            bool isDaylightSavings = false;
             isAmbiguousLocalDst = false;
-            TimeSpan baseOffset;
             int timeYear = time.Year;
 
             OffsetAndRule match = s_cachedData.GetOneYearLocalFromUtc(timeYear);
-            baseOffset = match.Offset;
+            TimeSpan baseOffset = match.Offset;
 
             if (match.Rule != null)
             {
                 baseOffset = baseOffset + match.Rule.BaseUtcOffsetDelta;
                 if (match.Rule.HasDaylightSaving)
                 {
-                    isDaylightSavings = GetIsDaylightSavingsFromUtc(time, timeYear, match.Offset, match.Rule, null, out isAmbiguousLocalDst, Local);
+                    bool isDaylightSavings = GetIsDaylightSavingsFromUtc(time, timeYear, match.Offset, match.Rule, null, out isAmbiguousLocalDst, Local);
                     baseOffset += (isDaylightSavings ? match.Rule.DaylightDelta : TimeSpan.Zero /* FUTURE: rule.StandardDelta */);
                 }
             }
+
             return baseOffset;
         }
 
index 02f0abf..bf8aec7 100644 (file)
@@ -1701,21 +1701,15 @@ namespace System
         /// Helper function that calculates the UTC offset for a UTC-dateTime in a timeZone.
         /// This function assumes that the dateTime is represented in UTC and has *not* already been converted into the timeZone.
         /// </summary>
-        private static TimeSpan GetUtcOffsetFromUtc(DateTime time, TimeZoneInfo zone)
-        {
-            bool isDaylightSavings;
-            return GetUtcOffsetFromUtc(time, zone, out isDaylightSavings);
-        }
+        private static TimeSpan GetUtcOffsetFromUtc(DateTime time, TimeZoneInfo zone) =>
+            GetUtcOffsetFromUtc(time, zone, out _);
 
         /// <summary>
         /// Helper function that calculates the UTC offset for a UTC-dateTime in a timeZone.
         /// This function assumes that the dateTime is represented in UTC and has *not* already been converted into the timeZone.
         /// </summary>
-        private static TimeSpan GetUtcOffsetFromUtc(DateTime time, TimeZoneInfo zone, out bool isDaylightSavings)
-        {
-            bool isAmbiguousLocalDst;
-            return GetUtcOffsetFromUtc(time, zone, out isDaylightSavings, out isAmbiguousLocalDst);
-        }
+        private static TimeSpan GetUtcOffsetFromUtc(DateTime time, TimeZoneInfo zone, out bool isDaylightSavings) =>
+            GetUtcOffsetFromUtc(time, zone, out isDaylightSavings, out _);
 
         /// <summary>
         /// Helper function that calculates the UTC offset for a UTC-dateTime in a timeZone.
@@ -1847,12 +1841,11 @@ namespace System
 
             TimeZoneInfoResult result = TimeZoneInfoResult.Success;
             e = null;
-            TimeZoneInfo? match = null;
 
             // check the cache
             if (cachedData._systemTimeZones != null)
             {
-                if (cachedData._systemTimeZones.TryGetValue(id, out match))
+                if (cachedData._systemTimeZones.TryGetValue(id, out TimeZoneInfo? match))
                 {
                     if (dstDisabled && match._supportsDaylightSavingTime)
                     {
@@ -1864,6 +1857,7 @@ namespace System
                         value = new TimeZoneInfo(match._id, match._baseUtcOffset, match._displayName, match._standardDisplayName,
                                               match._daylightDisplayName, match._adjustmentRules, disableDaylightSavingTime: false);
                     }
+
                     return result;
                 }
             }
index 308b57a..a9f2044 100644 (file)
@@ -104,9 +104,7 @@ namespace System
         // Returns the enum values as an object array.
         private Array GetEnumRawConstantValues()
         {
-            string[] names;
-            Array values;
-            GetEnumData(out names, out values);
+            GetEnumData(out _, out Array values);
             return values;
         }
 
index 0d7adf5..20e41d9 100644 (file)
@@ -150,7 +150,7 @@ namespace System
             EventInfo?[]? e = null;
             Type?[]? t = null;
 
-            int i = 0;
+            int i;
             int cnt = 0;            // Total Matchs
 
             // Check the methods