diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs index 77f64abd1b42c..9c32a327a2897 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs @@ -756,7 +756,7 @@ public LicenseInteropProxy() Type licContext = Type.GetType("System.ComponentModel.LicenseContext, System.ComponentModel.TypeConverter", throwOnError: true)!; _setSavedLicenseKey = licContext.GetMethod("SetSavedLicenseKey", BindingFlags.Instance | BindingFlags.Public)!; - _createWithContext = licManager.GetMethod("CreateWithContext", new[] { typeof(Type), licContext })!; + _createWithContext = licManager.GetMethod("CreateWithContext", [typeof(Type), licContext])!; Type interopHelper = licManager.GetNestedType("LicenseInteropHelper", BindingFlags.NonPublic)!; _validateTypeAndReturnDetails = interopHelper.GetMethod("ValidateAndRetrieveLicenseDetails", BindingFlags.Static | BindingFlags.Public)!; @@ -816,7 +816,7 @@ public void GetLicInfo(Type type, out bool runtimeKeyAvail, out bool licVerified licVerified = true; } - parameters = new object?[] { type.AssemblyQualifiedName }; + parameters = [type.AssemblyQualifiedName]; runtimeKeyAvail = (bool)_licInfoHelperContains.Invoke(licContext, BindingFlags.DoNotWrapExceptions, binder: null, parameters: parameters, culture: null)!; } @@ -867,18 +867,18 @@ public object AllocateAndValidateLicense([DynamicallyAccessedMembers(Dynamically object? licContext; if (isDesignTime) { - parameters = new object[] { type }; + parameters = [type]; licContext = _createDesignContext.Invoke(null, BindingFlags.DoNotWrapExceptions, binder: null, parameters: parameters, culture: null); } else { - parameters = new object?[] { type, key }; + parameters = [type, key]; licContext = _createRuntimeContext.Invoke(null, BindingFlags.DoNotWrapExceptions, binder: null, parameters: parameters, culture: null); } try { - parameters = new object?[] { type, licContext }; + parameters = [type, licContext]; return _createWithContext.Invoke(null, BindingFlags.DoNotWrapExceptions, binder: null, parameters: parameters, culture: null)!; } catch (Exception exception) when (exception.GetType() == s_licenseExceptionType) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs b/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs index 3e9d722d98eff..8e90b6a2eec6c 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/StackFrameHelper.cs @@ -110,12 +110,12 @@ internal void InitializeSourceInfo(int iSkip, bool fNeedFileInfo, Exception? exc return; } - Type[] parameterTypes = new Type[] - { + Type[] parameterTypes = + [ typeof(Assembly), typeof(string), typeof(IntPtr), typeof(int), typeof(bool), typeof(IntPtr), typeof(int), typeof(int), typeof(int), typeof(string).MakeByRefType(), typeof(int).MakeByRefType(), typeof(int).MakeByRefType() - }; + ]; MethodInfo? symbolsMethodInfo = symbolsType.GetMethod("GetSourceLineInfo", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, parameterTypes, null); if (symbolsMethodInfo == null) { diff --git a/src/coreclr/System.Private.CoreLib/src/System/Enum.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Enum.CoreCLR.cs index 066ca50e60497..fb369e9393f11 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Enum.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Enum.CoreCLR.cs @@ -33,7 +33,7 @@ private unsafe CorElementType InternalGetCorElementType() // Indexed by CorElementType private static readonly RuntimeType?[] s_underlyingTypes = - { + [ null, null, (RuntimeType)typeof(bool), @@ -60,7 +60,7 @@ private unsafe CorElementType InternalGetCorElementType() null, (RuntimeType)typeof(nint), (RuntimeType)typeof(nuint) - }; + ]; [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static unsafe RuntimeType InternalGetUnderlyingType(RuntimeType enumType) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs index 468f71204421f..72003736ff230 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttributeData.cs @@ -383,11 +383,10 @@ private void Init(TypeForwardedToAttribute forwardedTo) { Type type = typeof(TypeForwardedToAttribute); - Type[] sig = new Type[] { typeof(Type) }; + Type[] sig = [typeof(Type)]; m_ctor = type.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, sig, null)!; - CustomAttributeTypedArgument[] typedArgs = new CustomAttributeTypedArgument[1]; - typedArgs[0] = new CustomAttributeTypedArgument(typeof(Type), forwardedTo.Destination); + CustomAttributeTypedArgument[] typedArgs = [new CustomAttributeTypedArgument(typeof(Type), forwardedTo.Destination)]; m_typedCtorArgs = Array.AsReadOnly(typedArgs); m_namedArgs = Array.Empty(); @@ -1954,8 +1953,8 @@ internal static class PseudoCustomAttribute #region Static Constructor private static HashSet CreatePseudoCustomAttributeHashSet() { - Type[] pcas = new Type[] - { + Type[] pcas = + [ // See https://github.com/dotnet/runtime/blob/main/src/coreclr/md/compiler/custattr_emit.cpp typeof(FieldOffsetAttribute), // field typeof(SerializableAttribute), // class, struct, enum, delegate @@ -1968,7 +1967,7 @@ private static HashSet CreatePseudoCustomAttributeHashSet() typeof(DllImportAttribute), // method typeof(PreserveSigAttribute), // method typeof(TypeForwardedToAttribute), // assembly - }; + ]; HashSet set = new HashSet(pcas.Length); foreach (RuntimeType runtimeType in pcas) diff --git a/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs index 28c03245f6dde..90ad4bd92a01b 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs @@ -83,7 +83,7 @@ public T[] ToArray() if (_count == 0) return Array.Empty(); if (_count == 1) - return new T[1] { _item }; + return [_item]; Array.Resize(ref _items, _count); _capacity = _count; @@ -3569,7 +3569,7 @@ public override Type MakeGenericType(Type[] instantiation) } catch (TypeLoadException e) { - ValidateGenericArguments(this, new[] { rt }, e); + ValidateGenericArguments(this, [rt], e); throw; } } @@ -4036,7 +4036,7 @@ private extern object InvokeDispMethod( paramMod[i] = aArgsIsByRef[i]; } - aParamMod = new ParameterModifier[] { paramMod }; + aParamMod = [paramMod]; if (aArgsWrapperTypes != null) { WrapArgsForInvokeCall(aArgs, aArgsWrapperTypes); @@ -4124,11 +4124,11 @@ private static void WrapArgsForInvokeCall(object[] aArgs, int[] aArgsWrapperType ConstructorInfo wrapperCons; if (isString) { - wrapperCons = wrapperType.GetConstructor(new Type[] { typeof(string) })!; + wrapperCons = wrapperType.GetConstructor([typeof(string)])!; } else { - wrapperCons = wrapperType.GetConstructor(new Type[] { typeof(object) })!; + wrapperCons = wrapperType.GetConstructor([typeof(object)])!; } // Wrap each of the elements of the array. @@ -4136,11 +4136,11 @@ private static void WrapArgsForInvokeCall(object[] aArgs, int[] aArgsWrapperType { if (isString) { - newArray[currElem] = wrapperCons.Invoke(new object?[] { (string?)oldArray.GetValue(currElem) }); + newArray[currElem] = wrapperCons.Invoke([(string?)oldArray.GetValue(currElem)]); } else { - newArray[currElem] = wrapperCons.Invoke(new object?[] { oldArray.GetValue(currElem) }); + newArray[currElem] = wrapperCons.Invoke([oldArray.GetValue(currElem)]); } } diff --git a/src/coreclr/System.Private.CoreLib/src/System/__ComObject.cs b/src/coreclr/System.Private.CoreLib/src/System/__ComObject.cs index 2d9040f6dd9b2..77a88b59bff0b 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/__ComObject.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/__ComObject.cs @@ -124,7 +124,7 @@ private object CreateEventProvider( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] RuntimeType t) { // Create the event provider for the specified type. - object EvProvider = Activator.CreateInstance(t, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, new object[] { this }, null)!; + object EvProvider = Activator.CreateInstance(t, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, [this], null)!; // Attempt to cache the wrapper on the object. if (!SetData(t, EvProvider)) diff --git a/src/libraries/Common/src/System/Number.Formatting.Common.cs b/src/libraries/Common/src/System/Number.Formatting.Common.cs index 672ff2402682b..da0d7209ab307 100644 --- a/src/libraries/Common/src/System/Number.Formatting.Common.cs +++ b/src/libraries/Common/src/System/Number.Formatting.Common.cs @@ -20,37 +20,37 @@ internal static partial class Number private const string PosNumberFormat = "#"; private static readonly string[] s_posCurrencyFormats = - { + [ "$#", "#$", "$ #", "# $" - }; + ]; private static readonly string[] s_negCurrencyFormats = - { + [ "($#)", "-$#", "$-#", "$#-", "(#$)", "-#$", "#-$", "#$-", "-# $", "-$ #", "# $-", "$ #-", "$ -#", "#- $", "($ #)", "(# $)", "$- #" - }; + ]; private static readonly string[] s_posPercentFormats = - { + [ "# %", "#%", "%#", "% #" - }; + ]; private static readonly string[] s_negPercentFormats = - { + [ "-# %", "-#%", "-%#", "%-#", "%#-", "#-%", "#%-", "-% #", "# %-", "% #-", "% -#", "#- %" - }; + ]; private static readonly string[] s_negNumberFormats = - { + [ "(#)", "-#", "- #", "#-", "# -", - }; + ]; internal static unsafe char ParseFormatSpecifier(ReadOnlySpan format, out int digits) { diff --git a/src/libraries/Common/src/System/Runtime/InteropServices/ComEventsMethod.cs b/src/libraries/Common/src/System/Runtime/InteropServices/ComEventsMethod.cs index 24edd51671502..7f965abcea769 100644 --- a/src/libraries/Common/src/System/Runtime/InteropServices/ComEventsMethod.cs +++ b/src/libraries/Common/src/System/Runtime/InteropServices/ComEventsMethod.cs @@ -63,7 +63,7 @@ public DelegateWrapper(Delegate d, bool wrapArgs) } } - return Delegate.DynamicInvoke(WrapArgs ? new object[] { args } : args); + return Delegate.DynamicInvoke(WrapArgs ? [args] : args); } private void PreProcessSignature() diff --git a/src/libraries/System.Private.CoreLib/src/System/AggregateException.cs b/src/libraries/System.Private.CoreLib/src/System/AggregateException.cs index bdd6e87571275..5ff0ff2160a3f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/AggregateException.cs +++ b/src/libraries/System.Private.CoreLib/src/System/AggregateException.cs @@ -58,7 +58,7 @@ public AggregateException(string? message, Exception innerException) { ArgumentNullException.ThrowIfNull(innerException); - _innerExceptions = new[] { innerException }; + _innerExceptions = [innerException]; } /// diff --git a/src/libraries/System.Private.CoreLib/src/System/AppDomain.cs b/src/libraries/System.Private.CoreLib/src/System/AppDomain.cs index 2849756d131b4..2aa3539257f4a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/AppDomain.cs +++ b/src/libraries/System.Private.CoreLib/src/System/AppDomain.cs @@ -144,7 +144,7 @@ private static int ExecuteAssembly(Assembly assembly, string?[]? args) obj: null, invokeAttr: BindingFlags.DoNotWrapExceptions, binder: null, - parameters: entry.GetParametersAsSpan().Length > 0 ? new object?[] { args } : null, + parameters: entry.GetParametersAsSpan().Length > 0 ? [args] : null, culture: null); return result != null ? (int)result : 0; diff --git a/src/libraries/System.Private.CoreLib/src/System/Array.cs b/src/libraries/System.Private.CoreLib/src/System/Array.cs index 49e00054498d4..7d74af5d65c3a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Array.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Array.cs @@ -1065,9 +1065,9 @@ public void CopyTo(Array array, long index) private static class EmptyArray { -#pragma warning disable CA1825 // this is the implementation of Array.Empty() +#pragma warning disable CA1825, IDE0300 // this is the implementation of Array.Empty() internal static readonly T[] Value = new T[0]; -#pragma warning restore CA1825 +#pragma warning restore CA1825, IDE0300 } public static T[] Empty() diff --git a/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs b/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs index 5561c8ec3a420..e62a847e764eb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs @@ -33,9 +33,9 @@ namespace System // Do not replace the array allocation with Array.Empty. We don't want to have the overhead of // instantiating another generic type in addition to ArraySegment for new type parameters. -#pragma warning disable CA1825 +#pragma warning disable CA1825, IDE0300 public static ArraySegment Empty { get; } = new ArraySegment(new T[0]); -#pragma warning restore CA1825 +#pragma warning restore CA1825, IDE0300 private readonly T[]? _array; // Do not rename (binary serialization) private readonly int _offset; // Do not rename (binary serialization) diff --git a/src/libraries/System.Private.CoreLib/src/System/BitConverter.cs b/src/libraries/System.Private.CoreLib/src/System/BitConverter.cs index f35aa129d47f1..24069608615fb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/BitConverter.cs +++ b/src/libraries/System.Private.CoreLib/src/System/BitConverter.cs @@ -29,12 +29,7 @@ public static class BitConverter /// /// A Boolean value. /// A byte array with length 1. - public static byte[] GetBytes(bool value) - { - byte[] r = new byte[1]; - r[0] = (value ? (byte)1 : (byte)0); - return r; - } + public static byte[] GetBytes(bool value) => [(value ? (byte)1 : (byte)0)]; /// /// Converts a Boolean into a span of bytes. diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs index 7bee59109f1a4..119f06ac9fecf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs @@ -26,9 +26,9 @@ public class List : IList, IList, IReadOnlyList internal int _size; // Do not rename (binary serialization) internal int _version; // Do not rename (binary serialization) -#pragma warning disable CA1825 // avoid the extra generic instantiation for Array.Empty() +#pragma warning disable CA1825, IDE0300 // avoid the extra generic instantiation for Array.Empty() private static readonly T[] s_emptyArray = new T[0]; -#pragma warning restore CA1825 +#pragma warning restore CA1825, IDE0300 // Constructs a List. The list is initially empty and has a capacity // of zero. Upon adding the first element to the list the capacity is diff --git a/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs b/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs index ca15b1df6ea40..4b6d93f82fe01 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs @@ -2481,8 +2481,8 @@ public PowerOvfl(uint hi, uint mid, uint lo) } } - private static readonly PowerOvfl[] PowerOvflValues = new[] - { + private static readonly PowerOvfl[] PowerOvflValues = + [ // This is a table of the largest values that can be in the upper two // uints of a 96-bit number that will not overflow when multiplied // by a given power. For the upper word, this is a table of @@ -2497,7 +2497,7 @@ public PowerOvfl(uint hi, uint mid, uint lo) new PowerOvfl(4294, 4154504685, 2369172679), // 10^6 remainder 0.551616 new PowerOvfl(429, 2133437386, 4102387834), // 10^7 remainder 0.9551616 new PowerOvfl(42, 4078814305, 410238783), // 10^8 remainder 0.09991616 - }; + ]; [StructLayout(LayoutKind.Explicit)] private struct Buf12 diff --git a/src/libraries/System.Private.CoreLib/src/System/Decimal.cs b/src/libraries/System.Private.CoreLib/src/System/Decimal.cs index fc05bc065d492..240bcc7e5d632 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Decimal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Decimal.cs @@ -578,7 +578,7 @@ public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatPro // public static int[] GetBits(decimal d) { - return new int[] { (int)d.Low, (int)d.Mid, (int)d.High, d._flags }; + return [(int)d.Low, (int)d.Mid, (int)d.High, d._flags]; } /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Delegate.cs b/src/libraries/System.Private.CoreLib/src/System/Delegate.cs index 9e5a8170ac61c..a7133d3473a6c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Delegate.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Delegate.cs @@ -72,7 +72,7 @@ public abstract partial class Delegate : ICloneable, ISerializable protected virtual Delegate? RemoveImpl(Delegate d) => d.Equals(this) ? null : this; - public virtual Delegate[] GetInvocationList() => new Delegate[] { this }; + public virtual Delegate[] GetInvocationList() => [this]; /// /// Gets a value that indicates whether the has a single invocation target. diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs index 361f88fa360c3..b3b18d43f158c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/NullableAttributes.cs @@ -140,7 +140,7 @@ sealed class MemberNotNullAttribute : Attribute /// /// The field or property member that is promised to be not-null. /// - public MemberNotNullAttribute(string member) => Members = new[] { member }; + public MemberNotNullAttribute(string member) => Members = [member]; /// Initializes the attribute with the list of field and property members. /// @@ -171,7 +171,7 @@ sealed class MemberNotNullWhenAttribute : Attribute public MemberNotNullWhenAttribute(bool returnValue, string member) { ReturnValue = returnValue; - Members = new[] { member }; + Members = [member]; } /// Initializes the attribute with the specified return value condition and list of field and property members. diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs index 8def9abf8a7e0..7fdfef8f6d346 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs @@ -126,7 +126,7 @@ public StackTrace(Exception e, int skipFrames, bool fNeedFileInfo) /// public StackTrace(StackFrame frame) { - _stackFrames = new StackFrame[] { frame }; + _stackFrames = [frame]; _numOfFrames = 1; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeEventDispatcher.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeEventDispatcher.cs index f54eae0969803..c53bb2517927d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeEventDispatcher.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeEventDispatcher.cs @@ -96,10 +96,10 @@ private void CommitDispatchConfiguration() } // Enable the EventPipe session. - EventPipeProviderConfiguration[] providerConfiguration = new EventPipeProviderConfiguration[] - { + EventPipeProviderConfiguration[] providerConfiguration = + [ new EventPipeProviderConfiguration(NativeRuntimeEventSource.EventSourceName, (ulong)aggregatedKeywords, (uint)enableLevel, null) - }; + ]; ulong sessionID = EventPipeInternal.Enable(null, EventPipeSerializationFormat.NetTrace, DefaultEventListenerCircularMBSize, providerConfiguration); if (sessionID == 0) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs index c48a86fe32994..7d5365d8d2481 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs @@ -2200,7 +2200,7 @@ static TraceLoggingEventTypes GetTrimSafeTraceLoggingEventTypes() => string eventName = "EventSourceMessage"; EventParameterInfo paramInfo = default(EventParameterInfo); paramInfo.SetInfo("message", typeof(string)); - byte[]? metadata = EventPipeMetadataGenerator.Instance.GenerateMetadata(0, eventName, keywords, (uint)level, 0, EventOpcode.Info, new EventParameterInfo[] { paramInfo }); + byte[]? metadata = EventPipeMetadataGenerator.Instance.GenerateMetadata(0, eventName, keywords, (uint)level, 0, EventOpcode.Info, [paramInfo]); uint metadataLength = (metadata != null) ? (uint)metadata.Length : 0; fixed (byte* pMetadata = metadata) @@ -2958,7 +2958,7 @@ internal static bool IsCustomAttributeDefinedHelper( if (data.ConstructorArguments.Count == 1) { - attr = (Attribute?)Activator.CreateInstance(attributeType, new object?[] { data.ConstructorArguments[0].Value }); + attr = (Attribute?)Activator.CreateInstance(attributeType, [data.ConstructorArguments[0].Value]); } else if (data.ConstructorArguments.Count == 0) { @@ -5920,7 +5920,7 @@ private static void UpdateStringBuilder([NotNull] ref StringBuilder? stringBuild stringBuilder.Append(eventMessage, startIndex, count); } - private static readonly string[] s_escapes = { "&", "<", ">", "'", """, "%r", "%n", "%t" }; + private static readonly string[] s_escapes = ["&", "<", ">", "'", """, "%r", "%n", "%t"]; // Manifest messages use %N conventions for their message substitutions. Translate from // .NET conventions. We can't use RegEx for this (we are in mscorlib), so we do it 'by hand' private string TranslateToManifestConvention(string eventMessage, string evtName) diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs index f34961bab9ab2..14c2ad2b3d42e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/ConcurrentSet.cs @@ -70,7 +70,7 @@ public ItemType GetOrAdd(ItemType newItem) if (oldItems == null) { - newItems = new ItemType[] { newItem }; + newItems = [newItem]; } else { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs index 22af9e6927de8..415cd4d26884b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs @@ -405,7 +405,7 @@ private static bool EnumEraNames(string localeName, CalendarId calendarId, Calen // So for other calendars, only return the latest era. if (calendarId != CalendarId.JAPAN && calendarId != CalendarId.JAPANESELUNISOLAR && eraNames?.Length > 0) { - string[] latestEraName = new string[] { eraNames![eraNames.Length - 1] }; + string[] latestEraName = [eraNames![eraNames.Length - 1]]; eraNames = latestEraName; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.cs index b931ae5c89804..11b5b69f12922 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.cs @@ -69,22 +69,22 @@ private static CalendarData CreateInvariant() invariant.iCurrentEra = 1; // Current era # // Formats - invariant.saShortDates = new string[] { "MM/dd/yyyy", "yyyy-MM-dd" }; // short date format - invariant.saLongDates = new string[] { "dddd, dd MMMM yyyy" }; // long date format - invariant.saYearMonths = new string[] { "yyyy MMMM" }; // year month format + invariant.saShortDates = ["MM/dd/yyyy", "yyyy-MM-dd"]; // short date format + invariant.saLongDates = ["dddd, dd MMMM yyyy"]; // long date format + invariant.saYearMonths = ["yyyy MMMM"]; // year month format invariant.sMonthDay = "MMMM dd"; // Month day pattern // Calendar Parts Names - invariant.saEraNames = new string[] { "A.D." }; // Era names - invariant.saAbbrevEraNames = new string[] { "AD" }; // Abbreviated Era names - invariant.saAbbrevEnglishEraNames = new string[] { "AD" }; // Abbreviated era names in English - invariant.saDayNames = new string[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; // day names - invariant.saAbbrevDayNames = new string[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; // abbreviated day names - invariant.saSuperShortDayNames = new string[] { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" }; // The super short day names - invariant.saMonthNames = new string[] { "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December", string.Empty }; // month names - invariant.saAbbrevMonthNames = new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", string.Empty }; // abbreviated month names + invariant.saEraNames = ["A.D."]; // Era names + invariant.saAbbrevEraNames = ["AD"]; // Abbreviated Era names + invariant.saAbbrevEnglishEraNames = ["AD"]; // Abbreviated era names in English + invariant.saDayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; // day names + invariant.saAbbrevDayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; // abbreviated day names + invariant.saSuperShortDayNames = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]; // The super short day names + invariant.saMonthNames = [ "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December", string.Empty ]; // month names + invariant.saAbbrevMonthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", string.Empty ]; // abbreviated month names invariant.saMonthGenitiveNames = invariant.saMonthNames; // Genitive month names (same as month names for invariant) invariant.saAbbrevMonthGenitiveNames = invariant.saAbbrevMonthNames; // Abbreviated genitive month names (same as abbrev month names for invariant) invariant.saLeapYearMonthNames = invariant.saMonthNames; // leap year month names are unused in Gregorian English (invariant) @@ -165,7 +165,7 @@ internal CalendarData(string localeName, CalendarId calendarId, bool bUseUserOve else { // For all others just use the an empty string (doesn't matter we'll never ask for it for other calendars) - this.saAbbrevEnglishEraNames = new string[] { "" }; + this.saAbbrevEnglishEraNames = [""]; } // Japanese is the only thing with > 1 era. Its current era # is how many ever @@ -183,58 +183,58 @@ private void InitializeEraNames(string localeName, CalendarId calendarId) // Fallback for CoreCLR < Win7 or culture.dll missing if (AreEraNamesEmpty()) { - this.saEraNames = new string[] { "A.D." }; + this.saEraNames = ["A.D."]; } break; // The rest of the calendars have constant data, so we'll just use that case CalendarId.GREGORIAN_US: case CalendarId.JULIAN: - this.saEraNames = new string[] { "A.D." }; + this.saEraNames = ["A.D."]; break; case CalendarId.HEBREW: - this.saEraNames = new string[] { "C.E." }; + this.saEraNames = ["C.E."]; break; case CalendarId.HIJRI: case CalendarId.UMALQURA: if (localeName == "dv-MV") { // Special case for Divehi - this.saEraNames = new string[] { "\x0780\x07a8\x0796\x07b0\x0783\x07a9" }; + this.saEraNames = ["\x0780\x07a8\x0796\x07b0\x0783\x07a9"]; } else { - this.saEraNames = new string[] { "\x0628\x0639\x062F \x0627\x0644\x0647\x062C\x0631\x0629" }; + this.saEraNames = ["\x0628\x0639\x062F \x0627\x0644\x0647\x062C\x0631\x0629"]; } break; case CalendarId.GREGORIAN_ARABIC: case CalendarId.GREGORIAN_XLIT_ENGLISH: case CalendarId.GREGORIAN_XLIT_FRENCH: // These are all the same: - this.saEraNames = new string[] { "\x0645" }; + this.saEraNames = ["\x0645"]; break; case CalendarId.GREGORIAN_ME_FRENCH: - this.saEraNames = new string[] { "ap. J.-C." }; + this.saEraNames = ["ap. J.-C."]; break; case CalendarId.TAIWAN: if (SystemSupportsTaiwaneseCalendar()) { - this.saEraNames = new string[] { "\x4e2d\x83ef\x6c11\x570b" }; + this.saEraNames = ["\x4e2d\x83ef\x6c11\x570b"]; } else { - this.saEraNames = new string[] { string.Empty }; + this.saEraNames = [string.Empty]; } break; case CalendarId.KOREA: - this.saEraNames = new string[] { "\xb2e8\xae30" }; + this.saEraNames = ["\xb2e8\xae30"]; break; case CalendarId.THAI: - this.saEraNames = new string[] { "\x0e1e\x002e\x0e28\x002e" }; + this.saEraNames = ["\x0e1e\x002e\x0e28\x002e"]; break; case CalendarId.JAPAN: @@ -245,7 +245,7 @@ private void InitializeEraNames(string localeName, CalendarId calendarId) case CalendarId.PERSIAN: if (AreEraNamesEmpty()) { - this.saEraNames = new string[] { "\x0647\x002e\x0634" }; + this.saEraNames = ["\x0647\x002e\x0634"]; } break; @@ -276,14 +276,14 @@ private void InitializeAbbreviatedEraNames(string localeName, CalendarId calenda // Fallback for CoreCLR < Win7 or culture.dll missing if (this.saAbbrevEraNames == null || this.saAbbrevEraNames.Length == 0 || string.IsNullOrEmpty(this.saAbbrevEraNames[0])) { - this.saAbbrevEraNames = new string[] { "AD" }; + this.saAbbrevEraNames = ["AD"]; } break; // The rest of the calendars have constant data, so we'll just use that case CalendarId.GREGORIAN_US: case CalendarId.JULIAN: - this.saAbbrevEraNames = new string[] { "AD" }; + this.saAbbrevEraNames = ["AD"]; break; case CalendarId.JAPAN: case CalendarId.JAPANESELUNISOLAR: @@ -294,11 +294,11 @@ private void InitializeAbbreviatedEraNames(string localeName, CalendarId calenda if (localeName == "dv-MV") { // Special case for Divehi - this.saAbbrevEraNames = new string[] { "\x0780\x002e" }; + this.saAbbrevEraNames = ["\x0780\x002e"]; } else { - this.saAbbrevEraNames = new string[] { "\x0647\x0640" }; + this.saAbbrevEraNames = ["\x0647\x0640"]; } break; case CalendarId.TAIWAN: diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendricalCalculationsHelper.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendricalCalculationsHelper.cs index c50bbfd491f51..c389253bdf113 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendricalCalculationsHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendricalCalculationsHelper.cs @@ -88,8 +88,8 @@ public EphemerisCorrectionAlgorithmMap(int year, CorrectionAlgorithm algorithm) internal readonly CorrectionAlgorithm _algorithm; } - private static readonly EphemerisCorrectionAlgorithmMap[] s_ephemerisCorrectionTable = new EphemerisCorrectionAlgorithmMap[] - { + private static readonly EphemerisCorrectionAlgorithmMap[] s_ephemerisCorrectionTable = + [ // lowest year that starts algorithm, algorithm to use new EphemerisCorrectionAlgorithmMap(2020, CorrectionAlgorithm.Default), new EphemerisCorrectionAlgorithmMap(1988, CorrectionAlgorithm.Year1988to2019), @@ -98,7 +98,7 @@ public EphemerisCorrectionAlgorithmMap(int year, CorrectionAlgorithm algorithm) new EphemerisCorrectionAlgorithmMap(1700, CorrectionAlgorithm.Year1700to1799), new EphemerisCorrectionAlgorithmMap(1620, CorrectionAlgorithm.Year1620to1699), new EphemerisCorrectionAlgorithmMap(int.MinValue, CorrectionAlgorithm.Default) // default must be last - }; + ]; private static double Reminder(double divisor, double dividend) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/ChineseLunisolarCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/ChineseLunisolarCalendar.cs index 5742417a613ec..91a1c422a5592 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/ChineseLunisolarCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/ChineseLunisolarCalendar.cs @@ -296,6 +296,6 @@ public override int GetEra(DateTime time) // Use CAL_GREGORIAN just to get CurrentEraValue as 1 since we do not have data under the ID CAL_ChineseLunisolar yet CalendarId.GREGORIAN; - public override int[] Eras => new int[] { ChineseEra }; + public override int[] Eras => [ChineseEra]; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs index 4d0c7156238e6..2d6f5f687fa9e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs @@ -278,10 +278,10 @@ private int[] IcuGetLocaleInfo(LocaleGroupingData type) if (secondaryGroupingSize == 0) { - return new int[] { primaryGroupingSize }; + return [primaryGroupingSize]; } - return new int[] { primaryGroupingSize, secondaryGroupingSize }; + return [primaryGroupingSize, secondaryGroupingSize]; } private string IcuGetTimeFormatString() => IcuGetTimeFormatString(shortFormat: false); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Nls.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Nls.cs index a69b67f87c5fb..cb178278d9889 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Nls.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Nls.cs @@ -287,12 +287,12 @@ private static int[] ConvertWin32GroupString(string win32Str) // None of these cases make any sense if (string.IsNullOrEmpty(win32Str)) { - return new int[] { 3 }; + return [3]; } if (win32Str.StartsWith('0')) { - return new int[] { 0 }; + return [0]; } // Since its in n;n;n;n;n format, we can always get the length quickly @@ -316,7 +316,7 @@ private static int[] ConvertWin32GroupString(string win32Str) // Note that this # shouldn't ever be zero, 'cause 0 is only at end // But we'll test because its registry that could be anything if (!char.IsBetween(win32Str[i], '1', '9')) - return new int[] { 3 }; + return [3]; values[j] = (int)(win32Str[i] - '0'); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Windows.cs index b00eab023e93b..20ca77979cd0d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Windows.cs @@ -217,7 +217,7 @@ internal static unsafe CultureData GetCurrentRegionData() if (!_bUseOverrides) { - return new string[] { icuFormatString }; + return [icuFormatString]; } // When using ICU and need to get user overrides, we put the user override at the beginning @@ -226,7 +226,7 @@ internal static unsafe CultureData GetCurrentRegionData() Debug.Assert(!string.IsNullOrEmpty(userOverride)); return userOverride != icuFormatString ? - new string[] { userOverride, icuFormatString } : new string[] { userOverride }; + [userOverride, icuFormatString] : [userOverride]; } private int GetAnsiCodePage(string _ /*cultureName*/) => diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs index dba31f533c9ad..3c3cc47a322c3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -536,7 +536,7 @@ internal static CultureInfo[] GetCultures(CultureTypes types) if (GlobalizationMode.Invariant) { // in invariant mode we always return invariant culture only from the enumeration - return new CultureInfo[] { new CultureInfo("") }; + return [new CultureInfo("")]; } #pragma warning restore 618 @@ -585,7 +585,7 @@ private static CultureData CreateCultureWithInvariantData() invariant._sNegativeSign = "-"; // negative sign invariant._iDigits = 2; // number of fractional digits invariant._iNegativeNumber = 1; // negative number format - invariant._waGrouping = new int[] { 3 }; // grouping of digits + invariant._waGrouping = [3]; // grouping of digits invariant._sDecimalSeparator = "."; // decimal separator invariant._sThousandSeparator = ","; // thousands separator invariant._sNaN = "NaN"; // Not a Number @@ -606,7 +606,7 @@ private static CultureData CreateCultureWithInvariantData() invariant._iCurrencyDigits = 2; // # local monetary fractional digits invariant._iCurrency = 0; // positive currency format invariant._iNegativeCurrency = 0; // negative currency format - invariant._waMonetaryGrouping = new int[] { 3 }; // monetary grouping of digits + invariant._waMonetaryGrouping = [3]; // monetary grouping of digits invariant._sMonetaryDecimal = "."; // monetary decimal separator invariant._sMonetaryThousand = ","; // monetary thousands separator @@ -618,15 +618,15 @@ private static CultureData CreateCultureWithInvariantData() invariant._sTimeSeparator = ":"; invariant._sAM1159 = "AM"; // AM designator invariant._sPM2359 = "PM"; // PM designator - invariant._saLongTimes = new string[] { "HH:mm:ss" }; // time format - invariant._saShortTimes = new string[] { "HH:mm", "hh:mm tt", "H:mm", "h:mm tt" }; // short time format + invariant._saLongTimes = ["HH:mm:ss"]; // time format + invariant._saShortTimes = ["HH:mm", "hh:mm tt", "H:mm", "h:mm tt"]; // short time format // Calendar specific data invariant._iFirstDayOfWeek = 0; // first day of week invariant._iFirstWeekOfYear = 0; // first week of year // all available calendar type(s). The first one is the default calendar - invariant._waCalendars = new CalendarId[] { CalendarId.GREGORIAN }; + invariant._waCalendars = [CalendarId.GREGORIAN]; if (!GlobalizationMode.InvariantNoLoad) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs index 27901d8744813..1879f22b62da7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs @@ -144,7 +144,7 @@ internal static class DateTimeFormat private static readonly string[] s_invariantAbbreviatedMonthNames = InvariantFormatInfo.AbbreviatedMonthNames; private static readonly string[] s_invariantAbbreviatedDayNames = InvariantFormatInfo.AbbreviatedDayNames; - internal static string[] fixedNumberFormats = new string[] { + internal static readonly string[] fixedNumberFormats = [ "0", "00", "000", @@ -152,7 +152,7 @@ internal static class DateTimeFormat "00000", "000000", "0000000", - }; + ]; /// Format the positive integer value to a string and prefix with assigned length of leading zero. /// The type of the character. @@ -1759,7 +1759,7 @@ internal static string[] GetAllDateTimes(DateTime dateTime, char format, DateTim case 'O': case 's': case 'u': - results = new string[] { Format(dateTime, char.ToString(format), dtfi) }; + results = [Format(dateTime, char.ToString(format), dtfi)]; break; default: throw new FormatException(SR.Format_InvalidString); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormatInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormatInfo.cs index f2b99e5a81b3b..000548cc2b1cb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormatInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormatInfo.cs @@ -1323,18 +1323,18 @@ public string[] GetAllDateTimePatterns(char format) break; case 'm': case 'M': - result = new string[] { MonthDayPattern }; + result = [MonthDayPattern]; break; case 'o': case 'O': - result = new string[] { RoundtripFormat }; + result = [RoundtripFormat]; break; case 'r': case 'R': - result = new string[] { rfc1123Pattern }; + result = [rfc1123Pattern]; break; case 's': - result = new string[] { sortableDateTimePattern }; + result = [sortableDateTimePattern]; break; case 't': result = AllShortTimePatterns; @@ -1343,7 +1343,7 @@ public string[] GetAllDateTimePatterns(char format) result = AllLongTimePatterns; break; case 'u': - result = new string[] { UniversalSortableDateTimePattern }; + result = [UniversalSortableDateTimePattern]; break; case 'y': case 'Y': diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs index ce0d92fdcc099..5e55b3b1a1aef 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs @@ -337,67 +337,67 @@ internal enum DS //////////////////////////////////////////////////////////////////////////// // End NumEnd NumAmPm NumSpace NumDaySep NumTimesep MonthEnd MonthSpace MonthDSep NumDateSuff NumTimeSuff DayOfWeek YearSpace YearDateSep YearEnd TimeZone Era UTCTimeMark - private static readonly DS[][] s_dateParsingStates = { + private static readonly DS[][] s_dateParsingStates = [ // DS.BEGIN // DS.BEGIN -new DS[] { DS.BEGIN, DS.ERROR, DS.TX_N, DS.N, DS.D_Nd, DS.T_Nt, DS.ERROR, DS.D_M, DS.D_M, DS.D_S, DS.T_S, DS.BEGIN, DS.D_Y, DS.D_Y, DS.ERROR, DS.BEGIN, DS.BEGIN, DS.ERROR }, +[DS.BEGIN, DS.ERROR, DS.TX_N, DS.N, DS.D_Nd, DS.T_Nt, DS.ERROR, DS.D_M, DS.D_M, DS.D_S, DS.T_S, DS.BEGIN, DS.D_Y, DS.D_Y, DS.ERROR, DS.BEGIN, DS.BEGIN, DS.ERROR], // DS.N // DS.N -new DS[] { DS.ERROR, DS.DX_NN, DS.TX_NN, DS.NN, DS.D_NNd, DS.ERROR, DS.DX_NM, DS.D_NM, DS.D_MNd, DS.D_NDS, DS.ERROR, DS.N, DS.D_YN, DS.D_YNd, DS.DX_YN, DS.N, DS.N, DS.ERROR }, +[DS.ERROR, DS.DX_NN, DS.TX_NN, DS.NN, DS.D_NNd, DS.ERROR, DS.DX_NM, DS.D_NM, DS.D_MNd, DS.D_NDS, DS.ERROR, DS.N, DS.D_YN, DS.D_YNd, DS.DX_YN, DS.N, DS.N, DS.ERROR], // DS.NN // DS.NN -new DS[] { DS.DX_NN, DS.DX_NNN, DS.TX_NNN, DS.DX_NNN, DS.ERROR, DS.T_Nt, DS.DX_MNN, DS.DX_MNN, DS.ERROR, DS.ERROR, DS.T_S, DS.NN, DS.DX_NNY, DS.ERROR, DS.DX_NNY, DS.NN, DS.NN, DS.ERROR }, +[DS.DX_NN, DS.DX_NNN, DS.TX_NNN, DS.DX_NNN, DS.ERROR, DS.T_Nt, DS.DX_MNN, DS.DX_MNN, DS.ERROR, DS.ERROR, DS.T_S, DS.NN, DS.DX_NNY, DS.ERROR, DS.DX_NNY, DS.NN, DS.NN, DS.ERROR], // DS.D_Nd // DS.D_Nd -new DS[] { DS.ERROR, DS.DX_NN, DS.ERROR, DS.D_NN, DS.D_NNd, DS.ERROR, DS.DX_NM, DS.D_MN, DS.D_MNd, DS.ERROR, DS.ERROR, DS.D_Nd, DS.D_YN, DS.D_YNd, DS.DX_YN, DS.ERROR, DS.D_Nd, DS.ERROR }, +[DS.ERROR, DS.DX_NN, DS.ERROR, DS.D_NN, DS.D_NNd, DS.ERROR, DS.DX_NM, DS.D_MN, DS.D_MNd, DS.ERROR, DS.ERROR, DS.D_Nd, DS.D_YN, DS.D_YNd, DS.DX_YN, DS.ERROR, DS.D_Nd, DS.ERROR], // DS.D_NN // DS.D_NN -new DS[] { DS.DX_NN, DS.DX_NNN, DS.TX_N, DS.DX_NNN, DS.ERROR, DS.T_Nt, DS.DX_MNN, DS.DX_MNN, DS.ERROR, DS.DX_DS, DS.T_S, DS.D_NN, DS.DX_NNY, DS.ERROR, DS.DX_NNY, DS.ERROR, DS.D_NN, DS.ERROR }, +[DS.DX_NN, DS.DX_NNN, DS.TX_N, DS.DX_NNN, DS.ERROR, DS.T_Nt, DS.DX_MNN, DS.DX_MNN, DS.ERROR, DS.DX_DS, DS.T_S, DS.D_NN, DS.DX_NNY, DS.ERROR, DS.DX_NNY, DS.ERROR, DS.D_NN, DS.ERROR], // DS.D_NNd // DS.D_NNd -new DS[] { DS.ERROR, DS.DX_NNN, DS.DX_NNN, DS.DX_NNN, DS.ERROR, DS.ERROR, DS.DX_MNN, DS.DX_MNN, DS.ERROR, DS.DX_DS, DS.ERROR, DS.D_NNd, DS.DX_NNY, DS.ERROR, DS.DX_NNY, DS.ERROR, DS.D_NNd, DS.ERROR }, +[DS.ERROR, DS.DX_NNN, DS.DX_NNN, DS.DX_NNN, DS.ERROR, DS.ERROR, DS.DX_MNN, DS.DX_MNN, DS.ERROR, DS.DX_DS, DS.ERROR, DS.D_NNd, DS.DX_NNY, DS.ERROR, DS.DX_NNY, DS.ERROR, DS.D_NNd, DS.ERROR], // DS.D_M // DS.D_M -new DS[] { DS.ERROR, DS.DX_MN, DS.ERROR, DS.D_MN, DS.D_MNd, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_M, DS.D_YM, DS.D_YMd, DS.DX_YM, DS.ERROR, DS.D_M, DS.ERROR }, +[DS.ERROR, DS.DX_MN, DS.ERROR, DS.D_MN, DS.D_MNd, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_M, DS.D_YM, DS.D_YMd, DS.DX_YM, DS.ERROR, DS.D_M, DS.ERROR], // DS.D_MN // DS.D_MN -new DS[] { DS.DX_MN, DS.DX_MNN, DS.DX_MNN, DS.DX_MNN, DS.ERROR, DS.T_Nt, DS.ERROR, DS.ERROR, DS.ERROR, DS.DX_DS, DS.T_S, DS.D_MN, DS.DX_YMN, DS.ERROR, DS.DX_YMN, DS.ERROR, DS.D_MN, DS.ERROR }, +[DS.DX_MN, DS.DX_MNN, DS.DX_MNN, DS.DX_MNN, DS.ERROR, DS.T_Nt, DS.ERROR, DS.ERROR, DS.ERROR, DS.DX_DS, DS.T_S, DS.D_MN, DS.DX_YMN, DS.ERROR, DS.DX_YMN, DS.ERROR, DS.D_MN, DS.ERROR], // DS.D_NM // DS.D_NM -new DS[] { DS.DX_NM, DS.DX_MNN, DS.DX_MNN, DS.DX_MNN, DS.ERROR, DS.T_Nt, DS.ERROR, DS.ERROR, DS.ERROR, DS.DX_DS, DS.T_S, DS.D_NM, DS.DX_YMN, DS.ERROR, DS.DX_YMN, DS.ERROR, DS.D_NM, DS.ERROR }, +[DS.DX_NM, DS.DX_MNN, DS.DX_MNN, DS.DX_MNN, DS.ERROR, DS.T_Nt, DS.ERROR, DS.ERROR, DS.ERROR, DS.DX_DS, DS.T_S, DS.D_NM, DS.DX_YMN, DS.ERROR, DS.DX_YMN, DS.ERROR, DS.D_NM, DS.ERROR], // DS.D_MNd // DS.D_MNd -new DS[] { DS.ERROR, DS.DX_MNN, DS.ERROR, DS.DX_MNN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_MNd, DS.DX_YMN, DS.ERROR, DS.DX_YMN, DS.ERROR, DS.D_MNd, DS.ERROR }, +[DS.ERROR, DS.DX_MNN, DS.ERROR, DS.DX_MNN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_MNd, DS.DX_YMN, DS.ERROR, DS.DX_YMN, DS.ERROR, DS.D_MNd, DS.ERROR], // DS.D_NDS, // DS.D_NDS, -new DS[] { DS.DX_NDS, DS.DX_NNDS, DS.DX_NNDS, DS.DX_NNDS, DS.ERROR, DS.T_Nt, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_NDS, DS.T_S, DS.D_NDS, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_NDS, DS.ERROR }, +[DS.DX_NDS, DS.DX_NNDS, DS.DX_NNDS, DS.DX_NNDS, DS.ERROR, DS.T_Nt, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_NDS, DS.T_S, DS.D_NDS, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_NDS, DS.ERROR], // DS.D_Y // DS.D_Y -new DS[] { DS.ERROR, DS.DX_YN, DS.ERROR, DS.D_YN, DS.D_YNd, DS.ERROR, DS.DX_YM, DS.D_YM, DS.D_YMd, DS.D_YM, DS.ERROR, DS.D_Y, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_Y, DS.ERROR }, +[DS.ERROR, DS.DX_YN, DS.ERROR, DS.D_YN, DS.D_YNd, DS.ERROR, DS.DX_YM, DS.D_YM, DS.D_YMd, DS.D_YM, DS.ERROR, DS.D_Y, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_Y, DS.ERROR], // DS.D_YN // DS.D_YN -new DS[] { DS.DX_YN, DS.DX_YNN, DS.DX_YNN, DS.DX_YNN, DS.ERROR, DS.ERROR, DS.DX_YMN, DS.DX_YMN, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YN, DS.ERROR }, +[DS.DX_YN, DS.DX_YNN, DS.DX_YNN, DS.DX_YNN, DS.ERROR, DS.ERROR, DS.DX_YMN, DS.DX_YMN, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YN, DS.ERROR], // DS.D_YNd // DS.D_YNd -new DS[] { DS.ERROR, DS.DX_YNN, DS.DX_YNN, DS.DX_YNN, DS.ERROR, DS.ERROR, DS.DX_YMN, DS.DX_YMN, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YN, DS.ERROR }, +[DS.ERROR, DS.DX_YNN, DS.DX_YNN, DS.DX_YNN, DS.ERROR, DS.ERROR, DS.DX_YMN, DS.DX_YMN, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YN, DS.ERROR], // DS.D_YM // DS.D_YM -new DS[] { DS.DX_YM, DS.DX_YMN, DS.DX_YMN, DS.DX_YMN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YM, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YM, DS.ERROR }, +[DS.DX_YM, DS.DX_YMN, DS.DX_YMN, DS.DX_YMN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YM, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YM, DS.ERROR], // DS.D_YMd // DS.D_YMd -new DS[] { DS.ERROR, DS.DX_YMN, DS.DX_YMN, DS.DX_YMN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YM, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YM, DS.ERROR }, +[DS.ERROR, DS.DX_YMN, DS.DX_YMN, DS.DX_YMN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YM, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_YM, DS.ERROR], // DS.D_S // DS.D_S -new DS[] { DS.DX_DS, DS.DX_DSN, DS.TX_N, DS.T_Nt, DS.ERROR, DS.T_Nt, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_S, DS.T_S, DS.D_S, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_S, DS.ERROR }, +[DS.DX_DS, DS.DX_DSN, DS.TX_N, DS.T_Nt, DS.ERROR, DS.T_Nt, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_S, DS.T_S, DS.D_S, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_S, DS.ERROR], // DS.T_S // DS.T_S -new DS[] { DS.TX_TS, DS.TX_TS, DS.TX_TS, DS.T_Nt, DS.D_Nd, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_S, DS.T_S, DS.T_S, DS.ERROR, DS.ERROR, DS.ERROR, DS.T_S, DS.T_S, DS.ERROR }, +[DS.TX_TS, DS.TX_TS, DS.TX_TS, DS.T_Nt, DS.D_Nd, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.D_S, DS.T_S, DS.T_S, DS.ERROR, DS.ERROR, DS.ERROR, DS.T_S, DS.T_S, DS.ERROR], // DS.T_Nt // DS.T_Nt -new DS[] { DS.ERROR, DS.TX_NN, DS.TX_NN, DS.TX_NN, DS.ERROR, DS.T_NNt, DS.DX_NM, DS.D_NM, DS.ERROR, DS.ERROR, DS.T_S, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.T_Nt, DS.T_Nt, DS.TX_NN }, +[DS.ERROR, DS.TX_NN, DS.TX_NN, DS.TX_NN, DS.ERROR, DS.T_NNt, DS.DX_NM, DS.D_NM, DS.ERROR, DS.ERROR, DS.T_S, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.T_Nt, DS.T_Nt, DS.TX_NN], // DS.T_NNt // DS.T_NNt -new DS[] { DS.ERROR, DS.TX_NNN, DS.TX_NNN, DS.TX_NNN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.T_S, DS.T_NNt, DS.ERROR, DS.ERROR, DS.ERROR, DS.T_NNt, DS.T_NNt, DS.TX_NNN }, -}; +[DS.ERROR, DS.TX_NNN, DS.TX_NNN, DS.TX_NNN, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.ERROR, DS.T_S, DS.T_NNt, DS.ERROR, DS.ERROR, DS.ERROR, DS.T_NNt, DS.T_NNt, DS.TX_NNN], +]; // End NumEnd NumAmPm NumSpace NumDaySep NumTimesep MonthEnd MonthSpace MonthDSep NumDateSuff NumTimeSuff DayOfWeek YearSpace YearDateSep YearEnd TimeZone Era UTCMark internal const string GMTName = "GMT"; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/GregorianCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/GregorianCalendar.cs index 04baa4944bc73..11b61ae02b0a9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/GregorianCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/GregorianCalendar.cs @@ -232,7 +232,7 @@ public override int GetDaysInYear(int year, int era) public override int GetEra(DateTime time) => ADEra; - public override int[] Eras => new int[] { ADEra }; + public override int[] Eras => [ADEra]; /// /// Returns the month part of the specified DateTime. diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/HebrewCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/HebrewCalendar.cs index 95fec883d12a7..8ddfdbb488554 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/HebrewCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/HebrewCalendar.cs @@ -686,7 +686,7 @@ public override int GetDaysInYear(int year, int era) public override int GetEra(DateTime time) => HebrewEra; - public override int[] Eras => new int[] { HebrewEra }; + public override int[] Eras => [HebrewEra]; public override int GetMonth(DateTime time) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/HebrewNumber.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/HebrewNumber.cs index 94652898a521c..5df270d7283c2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/HebrewNumber.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/HebrewNumber.cs @@ -267,7 +267,7 @@ internal HebrewValue(HebrewToken token, short value) // Map a Hebrew character from U+05D0 ~ U+05EA to its digit value. // The value is -1 if the Hebrew character does not have a associated value. // - private static readonly HebrewValue[] s_hebrewValues = { + private static readonly HebrewValue[] s_hebrewValues = [ new HebrewValue(HebrewToken.Digit1, 1), // '\x05d0 new HebrewValue(HebrewToken.Digit1, 2), // '\x05d1 new HebrewValue(HebrewToken.Digit1, 3), // '\x05d2 @@ -295,7 +295,7 @@ internal HebrewValue(HebrewToken token, short value) new HebrewValue(HebrewToken.Digit200_300, 200), // '\x05e8; new HebrewValue(HebrewToken.Digit200_300, 300), // '\x05e9; new HebrewValue(HebrewToken.Digit400, 400), // '\x05ea; - }; + ]; private const int minHebrewNumberCh = 0x05d0; private static readonly char s_maxHebrewNumberCh = (char)(minHebrewNumberCh + s_hebrewValues.Length - 1); @@ -335,7 +335,7 @@ internal enum HS : sbyte // The state machine for Hebrew number passing. // private static readonly HS[] s_numberPassingState = - { + [ // 400 300/200 100 90~10 8~1 6, 7, 9, ' " /* 0 */ HS.S400, HS.X00, HS.X00, HS.X0, HS.X, HS.X, HS.X, HS.S9, HS._err, HS._err, @@ -371,7 +371,7 @@ internal enum HS : sbyte HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS._err, HS.S9_DQ, /* 16: S9_DQ */ HS._err, HS._err, HS._err, HS._err, HS._err, HS.END, HS.END, HS._err, HS._err, HS._err - }; + ]; // Count of valid HebrewToken, column count in the NumberPassingState array private const int HebrewTokenCount = 10; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/HijriCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/HijriCalendar.cs index 1fa6e4b4feae9..8608eeba2afef 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/HijriCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/HijriCalendar.cs @@ -344,7 +344,7 @@ public override int GetEra(DateTime time) return HijriEra; } - public override int[] Eras => new int[] { HijriEra }; + public override int[] Eras => [HijriEra]; public override int GetMonth(DateTime time) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseCalendar.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseCalendar.Icu.cs index 994a7b06b88bc..270179ea17543 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseCalendar.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseCalendar.Icu.cs @@ -8,7 +8,7 @@ namespace System.Globalization { public partial class JapaneseCalendar : Calendar { - private static readonly string[] s_abbreviatedEnglishEraNames = { "M", "T", "S", "H", "R" }; + private static readonly string[] s_abbreviatedEnglishEraNames = ["M", "T", "S", "H", "R"]; private static EraInfo[]? IcuGetJapaneseEras() { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/JulianCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/JulianCalendar.cs index 97d4875a4a4b4..3731ec31227d7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/JulianCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/JulianCalendar.cs @@ -252,7 +252,7 @@ public override int GetMonth(DateTime time) return GetDatePart(time.Ticks, DatePartMonth); } - public override int[] Eras => new int[] { JulianEra }; + public override int[] Eras => [JulianEra]; public override int GetMonthsInYear(int year, int era) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/KoreanCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/KoreanCalendar.cs index cb550395ba3c8..22a3a1380c2d3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/KoreanCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/KoreanCalendar.cs @@ -27,10 +27,10 @@ public class KoreanCalendar : Calendar // 1 = 2334 + yearOffset // So yearOffset = -2333 // Gregorian year 2001 is Korean year 4334. - private static readonly EraInfo[] s_koreanEraInfo = new EraInfo[] - { + private static readonly EraInfo[] s_koreanEraInfo = + [ new EraInfo(1, 1, 1, 1, -2333, 2334, GregorianCalendar.MaxYear + 2333) // era #, start year/month/day, yearOffset, minEraYear - }; + ]; private readonly GregorianCalendarHelper _helper; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/KoreanLunisolarCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/KoreanLunisolarCalendar.cs index a163abea35e06..c261a5f150e09 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/KoreanLunisolarCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/KoreanLunisolarCalendar.cs @@ -1229,6 +1229,6 @@ public override int GetEra(DateTime time) internal override CalendarId ID => CalendarId.KOREANLUNISOLAR; - public override int[] Eras => new int[] { GregorianEra }; + public override int[] Eras => [GregorianEra]; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/OrdinalCasing.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/OrdinalCasing.Icu.cs index 1d520c348723d..e8d6caf5b2b98 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/OrdinalCasing.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/OrdinalCasing.Icu.cs @@ -17,7 +17,7 @@ internal static partial class OrdinalCasing // s_basicLatin is covering the casing for the Basic Latin & C0 Controls range. // we are not lazy initializing this range because it is the most common used range and we'll cache it anyway very early. private static readonly ushort[] s_basicLatin = - { + [ // Upper Casing /* 0000-000f */ 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, @@ -36,7 +36,7 @@ internal static partial class OrdinalCasing /* 00d0-00df */ 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, /* 00e0-00ef */ 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, /* 00f0-00ff */ 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00f7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x0178, - }; + ]; // s_casingTable is covering the Unicode BMP plane only. Surrogate casing is handled separately. // Every cell in the table is covering the casing of 256 characters in the BMP. diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/PersianCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/PersianCalendar.cs index cc21367542fab..49bb2307eaa45 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/PersianCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/PersianCalendar.cs @@ -303,7 +303,7 @@ public override int GetEra(DateTime time) return PersianEra; } - public override int[] Eras => new int[] { PersianEra }; + public override int[] Eras => [PersianEra]; public override int GetMonth(DateTime time) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/TaiwanCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/TaiwanCalendar.cs index ae935e6011a94..e82680b4b1eb8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/TaiwanCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/TaiwanCalendar.cs @@ -22,10 +22,10 @@ public class TaiwanCalendar : Calendar // When Gregorian Year 1912 is year 1, so that // 1912 = 1 + yearOffset // So yearOffset = 1911 - private static readonly EraInfo[] s_taiwanEraInfo = new EraInfo[] - { + private static readonly EraInfo[] s_taiwanEraInfo = + [ new EraInfo(1, 1912, 1, 1, 1911, 1, GregorianCalendar.MaxYear - 1911) // era #, start year/month/day, yearOffset, minEraYear - }; + ]; private static Calendar? s_defaultInstance; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/TaiwanLunisolarCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/TaiwanLunisolarCalendar.cs index b52592cbfc874..148df55d70d73 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/TaiwanLunisolarCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/TaiwanLunisolarCalendar.cs @@ -17,10 +17,10 @@ public class TaiwanLunisolarCalendar : EastAsianLunisolarCalendar // When Gregorian Year 1912 is year 1, so that // 1912 = 1 + yearOffset // So yearOffset = 1911 - private static readonly EraInfo[] s_taiwanLunisolarEraInfo = new EraInfo[] - { + private static readonly EraInfo[] s_taiwanLunisolarEraInfo = + [ new EraInfo(1, 1912, 1, 1, 1911, 1, GregorianCalendar.MaxYear - 1911) // era #, start year/month/day, yearOffset, minEraYear - }; + ]; private readonly GregorianCalendarHelper _helper; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/ThaiBuddhistCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/ThaiBuddhistCalendar.cs index 4d0baa3356631..422b68071b775 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/ThaiBuddhistCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/ThaiBuddhistCalendar.cs @@ -16,10 +16,10 @@ namespace System.Globalization /// public class ThaiBuddhistCalendar : Calendar { - private static readonly EraInfo[] s_thaiBuddhistEraInfo = new EraInfo[] - { + private static readonly EraInfo[] s_thaiBuddhistEraInfo = + [ new EraInfo(1, 1, 1, 1, -543, 544, GregorianCalendar.MaxYear + 543) // era #, start year/month/day, yearOffset, minEraYear - }; + ]; public const int ThaiBuddhistEra = 1; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/UmAlQuraCalendar.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/UmAlQuraCalendar.cs index c90fd203c211b..96518b287303e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/UmAlQuraCalendar.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/UmAlQuraCalendar.cs @@ -510,7 +510,7 @@ public override int GetEra(DateTime time) return UmAlQuraEra; } - public override int[] Eras => new int[] { UmAlQuraEra }; + public override int[] Eras => [UmAlQuraEra]; public override int GetMonth(DateTime time) { diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs index 9b2977fa51b86..c97d7a9f00626 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs @@ -12,23 +12,23 @@ public static unsafe partial class Path { private static volatile delegate* unmanaged s_GetTempPathWFunc; - public static char[] GetInvalidFileNameChars() => new char[] - { + public static char[] GetInvalidFileNameChars() => + [ '\"', '<', '>', '|', '\0', (char)1, (char)2, (char)3, (char)4, (char)5, (char)6, (char)7, (char)8, (char)9, (char)10, (char)11, (char)12, (char)13, (char)14, (char)15, (char)16, (char)17, (char)18, (char)19, (char)20, (char)21, (char)22, (char)23, (char)24, (char)25, (char)26, (char)27, (char)28, (char)29, (char)30, (char)31, ':', '*', '?', '\\', '/' - }; + ]; - public static char[] GetInvalidPathChars() => new char[] - { + public static char[] GetInvalidPathChars() => + [ '|', '\0', (char)1, (char)2, (char)3, (char)4, (char)5, (char)6, (char)7, (char)8, (char)9, (char)10, (char)11, (char)12, (char)13, (char)14, (char)15, (char)16, (char)17, (char)18, (char)19, (char)20, (char)21, (char)22, (char)23, (char)24, (char)25, (char)26, (char)27, (char)28, (char)29, (char)30, (char)31 - }; + ]; private static bool ExistsCore(string fullPath, out bool isDirectory) { diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs index 47d847f351d2e..1af85eed92d91 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs @@ -931,7 +931,7 @@ public virtual void Write(ReadOnlySpan buffer) } } - public virtual void WriteByte(byte value) => Write(new byte[1] { value }, 0, 1); + public virtual void WriteByte(byte value) => Write([value], 0, 1); public static Stream Synchronized(Stream stream) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs index 7440e1fae8dac..14d377a6b09ae 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyName.cs @@ -174,7 +174,7 @@ private static Func InitGetAssemblyName() "GetAssemblyName", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static, null, - new Type[] { typeof(string) }, + [typeof(string)], null); if (getAssemblyNameMethod == null) diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs index 7a0c6461146c4..d64ccd64a482e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs @@ -362,7 +362,7 @@ public override object[] GetCustomAttributes(Type attributeType, bool inherit) public override object[] GetCustomAttributes(bool inherit) { // support for MethodImplAttribute PCA - return new object[] { new MethodImplAttribute((MethodImplOptions)GetMethodImplementationFlags()) }; + return [new MethodImplAttribute((MethodImplOptions)GetMethodImplementationFlags())]; } public override bool IsDefined(Type attributeType, bool inherit) diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs index 826fda1e2c5a0..096824b9d1e74 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs @@ -105,7 +105,7 @@ public virtual void ThrowException([DynamicallyAccessedMembers(DynamicallyAccess } private const string ConsoleTypeFullName = "System.Console, System.Console"; - private static readonly Type[] s_parameterTypes = new Type[] { typeof(string) }; + private static readonly Type[] s_parameterTypes = [typeof(string)]; public virtual void EmitWriteLine(string value) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/EventInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/EventInfo.cs index a42feec69e5d5..49fdffe27b9c0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/EventInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/EventInfo.cs @@ -66,7 +66,7 @@ public virtual void AddEventHandler(object? target, Delegate? handler) if (addMethod == null) throw new InvalidOperationException(SR.InvalidOperation_NoPublicAddMethod); - addMethod.Invoke(target, new object?[] { handler }); + addMethod.Invoke(target, [handler]); } [DebuggerHidden] @@ -78,7 +78,7 @@ public virtual void RemoveEventHandler(object? target, Delegate? handler) if (removeMethod == null) throw new InvalidOperationException(SR.InvalidOperation_NoPublicRemoveMethod); - removeMethod.Invoke(target, new object?[] { handler }); + removeMethod.Invoke(target, [handler]); } public override bool Equals(object? obj) => base.Equals(obj); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/InvokerEmitUtil.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/InvokerEmitUtil.cs index 30745bdcd708d..45853ff96a5a5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/InvokerEmitUtil.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/InvokerEmitUtil.cs @@ -23,7 +23,7 @@ public static unsafe InvokeFunc_Obj4Args CreateInvokeDelegate_Obj4Args(MethodBas bool emitNew = method is RuntimeConstructorInfo; bool hasThis = !emitNew && !method.IsStatic; - Type[] delegateParameters = new Type[5] { typeof(object), typeof(object), typeof(object), typeof(object), typeof(object) }; + Type[] delegateParameters = [typeof(object), typeof(object), typeof(object), typeof(object), typeof(object)]; string declaringTypeName = method.DeclaringType != null ? method.DeclaringType.Name + "." : string.Empty; var dm = new DynamicMethod( @@ -91,7 +91,7 @@ public static unsafe InvokeFunc_ObjSpanArgs CreateInvokeDelegate_ObjSpanArgs(Met bool hasThis = !emitNew && !method.IsStatic; // The first parameter is unused but supports treating the DynamicMethod as an instance method which is slightly faster than a static. - Type[] delegateParameters = new Type[2] { typeof(object), typeof(Span) }; + Type[] delegateParameters = [typeof(object), typeof(Span)]; string declaringTypeName = method.DeclaringType != null ? method.DeclaringType.Name + "." : string.Empty; var dm = new DynamicMethod( @@ -148,7 +148,7 @@ public static unsafe InvokeFunc_RefArgs CreateInvokeDelegate_RefArgs(MethodBase bool hasThis = !(emitNew || method.IsStatic); // The first parameter is unused but supports treating the DynamicMethod as an instance method which is slightly faster than a static. - Type[] delegateParameters = new Type[3] { typeof(object), typeof(object), typeof(IntPtr*) }; + Type[] delegateParameters = [typeof(object), typeof(object), typeof(IntPtr*)]; string declaringTypeName = method.DeclaringType != null ? method.DeclaringType.Name + "." : string.Empty; var dm = new DynamicMethod( @@ -339,11 +339,11 @@ public static MethodInfo Object_GetRawData() => private static MethodInfo? s_Pointer_Box; public static MethodInfo Pointer_Box() => - s_Pointer_Box ??= typeof(Pointer).GetMethod(nameof(Pointer.Box), new[] { typeof(void*), typeof(Type) })!; + s_Pointer_Box ??= typeof(Pointer).GetMethod(nameof(Pointer.Box), [typeof(void*), typeof(Type)])!; private static MethodInfo? s_Type_GetTypeFromHandle; public static MethodInfo Type_GetTypeFromHandle() => - s_Type_GetTypeFromHandle ??= typeof(Type).GetMethod(nameof(Type.GetTypeFromHandle), new[] { typeof(RuntimeTypeHandle) })!; + s_Type_GetTypeFromHandle ??= typeof(Type).GetMethod(nameof(Type.GetTypeFromHandle), [typeof(RuntimeTypeHandle)])!; #if MONO private static MethodInfo? s_DisableInline; diff --git a/src/libraries/System.Private.CoreLib/src/System/Resources/FileBasedResourceGroveler.cs b/src/libraries/System.Private.CoreLib/src/System/Resources/FileBasedResourceGroveler.cs index 159104801b643..df600abc3a8ba 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Resources/FileBasedResourceGroveler.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Resources/FileBasedResourceGroveler.cs @@ -93,8 +93,7 @@ private ResourceSet CreateResourceSet(string file) } else { - object[] args = new object[1]; - args[0] = file; + object[] args = [file]; try { return (ResourceSet)Activator.CreateInstance(_mediator.UserResourceSet, args)!; diff --git a/src/libraries/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.cs b/src/libraries/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.cs index 7cfe087de94cb..b390d7eb39f83 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Resources/ManifestBasedResourceGroveler.cs @@ -246,9 +246,7 @@ internal ResourceSet CreateResourceSet(Stream store, Assembly assembly) } else { - object[] args = new object[2]; - args[0] = store; - args[1] = assembly; + object[] args = [store, assembly]; try { // Add in a check for a constructor taking in an assembly first. @@ -291,14 +289,11 @@ private static ResourceSet InternalGetResourceSetFromSerializedData(Stream store else { Type readerType = Type.GetType(readerTypeName, throwOnError: true)!; - object[] args = new object[1]; - args[0] = store; + object[] args = [store]; reader = (IResourceReader)Activator.CreateInstance(readerType, args)!; } - object[] resourceSetArgs = new object[1]; - resourceSetArgs[0] = reader; - + object[] resourceSetArgs = [reader]; Type? resSetType = mediator.UserResourceSet; if (resSetType == null) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.Core.cs b/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.Core.cs index 47023b845924e..80e7c851145ed 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.Core.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.Core.cs @@ -102,7 +102,7 @@ private bool InitializeBinaryFormatter() if (Volatile.Read(ref s_binaryFormatterType) is null || Volatile.Read(ref s_deserializeMethod) is null) { Type binaryFormatterType = Type.GetType("System.Runtime.Serialization.Formatters.Binary.BinaryFormatter, System.Runtime.Serialization.Formatters", throwOnError: true)!; - MethodInfo? binaryFormatterDeserialize = binaryFormatterType.GetMethod("Deserialize", new[] { typeof(Stream) }); + MethodInfo? binaryFormatterDeserialize = binaryFormatterType.GetMethod("Deserialize", [typeof(Stream)]); Func? deserializeMethod = (Func?) typeof(ResourceReader) .GetMethod(nameof(CreateUntypedDelegate), BindingFlags.NonPublic | BindingFlags.Static) diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/InterpolatedStringHandlerArgumentAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/InterpolatedStringHandlerArgumentAttribute.cs index f9bbe890ca325..e17755573d705 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/InterpolatedStringHandlerArgumentAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/InterpolatedStringHandlerArgumentAttribute.cs @@ -10,7 +10,7 @@ public sealed class InterpolatedStringHandlerArgumentAttribute : Attribute /// Initializes a new instance of the class. /// The name of the argument that should be passed to the handler. /// The empty string may be used as the name of the receiver in an instance method. - public InterpolatedStringHandlerArgumentAttribute(string argument) => Arguments = new string[] { argument }; + public InterpolatedStringHandlerArgumentAttribute(string argument) => Arguments = [argument]; /// Initializes a new instance of the class. /// The names of the arguments that should be passed to the handler. diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/NullableAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/NullableAttribute.cs index 8b6e713cadae1..7e855514dad84 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/NullableAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/NullableAttribute.cs @@ -20,7 +20,7 @@ public sealed class NullableAttribute : Attribute /// The flags value. public NullableAttribute(byte value) { - NullableFlags = new[] { value }; + NullableFlags = [value]; } /// Initializes the attribute. diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs index 6e523ab9a2e4b..e4e6f2269a070 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs @@ -104,7 +104,7 @@ public AssemblyDependencyResolver(string componentAssemblyPath) _nativeSearchPaths = SplitPathsList(nativeSearchPathsList); _resourceSearchPaths = SplitPathsList(resourceSearchPathsList); - _assemblyDirectorySearchPaths = new string[1] { Path.GetDirectoryName(componentAssemblyPath)! }; + _assemblyDirectorySearchPaths = [Path.GetDirectoryName(componentAssemblyPath)!]; } public string? ResolveAssemblyToPath(AssemblyName assemblyName) diff --git a/src/libraries/System.Private.CoreLib/src/System/RuntimeType.cs b/src/libraries/System.Private.CoreLib/src/System/RuntimeType.cs index a4cfbaee8f29a..23cf3d8144fc0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/RuntimeType.cs +++ b/src/libraries/System.Private.CoreLib/src/System/RuntimeType.cs @@ -650,7 +650,7 @@ public override bool IsAssignableFrom([NotNullWhen(true)] Type? c) return finalist.Invoke(target, bindingFlags, binder, providedArgs, culture); } - finalists ??= new MethodInfo[] { finalist }; + finalists ??= [finalist]; providedArgs ??= Array.Empty(); object? state = null; MethodBase? invokeMethod = null; diff --git a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any1SearchValues.cs b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any1SearchValues.cs index 46156d7df92c4..9a947c2f15ce4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any1SearchValues.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any1SearchValues.cs @@ -24,7 +24,7 @@ public unsafe Any1SearchValues(ReadOnlySpan values) internal override unsafe T[] GetValues() { TImpl e0 = _e0; - return new[] { *(T*)&e0 }; + return [*(T*)&e0]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any2SearchValues.cs b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any2SearchValues.cs index 8cbec8897a87f..f79f2025224d3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any2SearchValues.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any2SearchValues.cs @@ -24,7 +24,7 @@ public unsafe Any2SearchValues(ReadOnlySpan values) internal override unsafe T[] GetValues() { TImpl e0 = _e0, e1 = _e1; - return new[] { *(T*)&e0, *(T*)&e1 }; + return [*(T*)&e0, *(T*)&e1]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any3SearchValues.cs b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any3SearchValues.cs index 8b3d29775cca9..082d02947d16a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any3SearchValues.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any3SearchValues.cs @@ -24,7 +24,7 @@ public unsafe Any3SearchValues(ReadOnlySpan values) internal override unsafe T[] GetValues() { TImpl e0 = _e0, e1 = _e1, e2 = _e2; - return new[] { *(T*)&e0, *(T*)&e1, *(T*)&e2 }; + return [*(T*)&e0, *(T*)&e1, *(T*)&e2]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any4SearchValues.cs b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any4SearchValues.cs index 17584c362a96b..dd3743f8f3228 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any4SearchValues.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any4SearchValues.cs @@ -24,7 +24,7 @@ public unsafe Any4SearchValues(ReadOnlySpan values) internal override unsafe T[] GetValues() { TImpl e0 = _e0, e1 = _e1, e2 = _e2, e3 = _e3; - return new[] { *(T*)&e0, *(T*)&e1, *(T*)&e2, *(T*)&e3 }; + return [*(T*)&e0, *(T*)&e1, *(T*)&e2, *(T*)&e3]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any5SearchValues.cs b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any5SearchValues.cs index 30c60c6971674..2bbb07bc4cf28 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any5SearchValues.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Any5SearchValues.cs @@ -24,7 +24,7 @@ public unsafe Any5SearchValues(ReadOnlySpan values) internal override unsafe T[] GetValues() { TImpl e0 = _e0, e1 = _e1, e2 = _e2, e3 = _e3, e4 = _e4; - return new[] { *(T*)&e0, *(T*)&e1, *(T*)&e2, *(T*)&e3, *(T*)&e4 }; + return [*(T*)&e0, *(T*)&e1, *(T*)&e2, *(T*)&e3, *(T*)&e4]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/SingleStringSearchValuesThreeChars.cs b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/SingleStringSearchValuesThreeChars.cs index cadfa9f1022ce..0060261777b9a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/SingleStringSearchValuesThreeChars.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/SingleStringSearchValuesThreeChars.cs @@ -384,6 +384,6 @@ internal override bool ContainsCore(string value) => HasUniqueValues internal override string[] GetValues() => HasUniqueValues ? base.GetValues() - : new string[] { _value }; + : [_value]; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs b/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs index f4e9d47be5f14..267ed51252c8d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs @@ -19,15 +19,15 @@ public sealed class SecurityElement private const int ChildrenTypical = 1; private const string EscapeChars = "<>\"'&"; - private static readonly string[] s_escapeStringPairs = new string[] - { + private static readonly string[] s_escapeStringPairs = + [ // these must be all once character escape sequences or a new escaping algorithm is needed "<", "<", ">", ">", "\"", """, "\'", "'", "&", "&" - }; + ]; //-------------------------- Constructors --------------------------- diff --git a/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs b/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs index 707b25442029a..19c08b3a75175 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.Manipulation.cs @@ -1841,7 +1841,7 @@ private string[] CreateSplitArrayOfThisAsSoleValue(StringSplitOptions options, i if ((options & StringSplitOptions.RemoveEmptyEntries) == 0 || candidate.Length != 0) { - return new string[] { candidate }; + return [candidate]; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs index 95ebfdc7737eb..e60a5eca24b1c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs @@ -1347,7 +1347,7 @@ internal unsafe byte GetNextByte() internal bool Fallback(byte fallbackByte) { // Build our buffer - byte[] byteBuffer = new byte[] { fallbackByte }; + byte[] byteBuffer = [fallbackByte]; // Do the fallback and add the data. return Fallback(byteBuffer); @@ -1356,7 +1356,7 @@ internal bool Fallback(byte fallbackByte) internal bool Fallback(byte byte1, byte byte2) { // Build our buffer - byte[] byteBuffer = new byte[] { byte1, byte2 }; + byte[] byteBuffer = [byte1, byte2]; // Do the fallback and add the data. return Fallback(byteBuffer); @@ -1365,7 +1365,7 @@ internal bool Fallback(byte byte1, byte byte2) internal bool Fallback(byte byte1, byte byte2, byte byte3, byte byte4) { // Build our buffer - byte[] byteBuffer = new byte[] { byte1, byte2, byte3, byte4 }; + byte[] byteBuffer = [byte1, byte2, byte3, byte4]; // Do the fallback and add the data. return Fallback(byteBuffer); diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/EncodingProvider.cs b/src/libraries/System.Private.CoreLib/src/System/Text/EncodingProvider.cs index b939492ed9753..ad56ef5b64b6e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/EncodingProvider.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/EncodingProvider.cs @@ -52,7 +52,7 @@ internal static void AddProvider(EncodingProvider provider) // object allocation on the startup path. if (s_providers is null && - Interlocked.CompareExchange(ref s_providers, new EncodingProvider[1] { provider }, null) is null) + Interlocked.CompareExchange(ref s_providers, [provider], null) is null) { return; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/UTF32Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/UTF32Encoding.cs index 0b2eb2061f7d8..41031f7734480 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/UTF32Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/UTF32Encoding.cs @@ -755,15 +755,15 @@ internal override unsafe int GetCharCount(byte* bytes, int count, DecoderNLS? ba byte[] fallbackBytes; if (_bigEndian) { - fallbackBytes = new byte[] { + fallbackBytes = [ unchecked((byte)(iChar >> 24)), unchecked((byte)(iChar >> 16)), - unchecked((byte)(iChar >> 8)), unchecked((byte)(iChar)) }; + unchecked((byte)(iChar >> 8)), unchecked((byte)(iChar)) ]; } else { - fallbackBytes = new byte[] { + fallbackBytes = [ unchecked((byte)(iChar)), unchecked((byte)(iChar >> 8)), - unchecked((byte)(iChar >> 16)), unchecked((byte)(iChar >> 24)) }; + unchecked((byte)(iChar >> 16)), unchecked((byte)(iChar >> 24)) ]; } charCount += fallbackBuffer.InternalFallback(fallbackBytes, bytes); @@ -904,15 +904,15 @@ internal override unsafe int GetChars(byte* bytes, int byteCount, byte[] fallbackBytes; if (_bigEndian) { - fallbackBytes = new byte[] { + fallbackBytes = [ unchecked((byte)(iChar >> 24)), unchecked((byte)(iChar >> 16)), - unchecked((byte)(iChar >> 8)), unchecked((byte)(iChar)) }; + unchecked((byte)(iChar >> 8)), unchecked((byte)(iChar)) ]; } else { - fallbackBytes = new byte[] { + fallbackBytes = [ unchecked((byte)(iChar)), unchecked((byte)(iChar >> 8)), - unchecked((byte)(iChar >> 16)), unchecked((byte)(iChar >> 24)) }; + unchecked((byte)(iChar >> 16)), unchecked((byte)(iChar >> 24)) ]; } // Chars won't be updated unless this works. @@ -1117,11 +1117,11 @@ public override byte[] GetPreamble() // Allocate new array to prevent users from modifying it. if (_bigEndian) { - return new byte[4] { 0x00, 0x00, 0xFE, 0xFF }; + return [0x00, 0x00, 0xFE, 0xFF]; } else { - return new byte[4] { 0xFF, 0xFE, 0x00, 0x00 }; // 00 00 FE FF + return [0xFF, 0xFE, 0x00, 0x00]; // 00 00 FE FF } } else diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs index 8ae01e85af9fe..d1f79b49370fe 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs @@ -863,7 +863,7 @@ public override byte[] GetPreamble() if (_emitUTF8Identifier) { // Allocate new array to prevent users from modifying it. - return new byte[3] { 0xEF, 0xBB, 0xBF }; + return [0xEF, 0xBB, 0xBF]; } else return Array.Empty(); diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/UnicodeEncoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/UnicodeEncoding.cs index 7d7c6f62d5851..7eaf078feae5a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/UnicodeEncoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/UnicodeEncoding.cs @@ -1133,13 +1133,11 @@ internal sealed override unsafe int GetCharCount(byte* bytes, int count, Decoder byte[]? byteBuffer = null; if (bigEndian) { - byteBuffer = new byte[] - { unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar) }; + byteBuffer = [unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar)]; } else { - byteBuffer = new byte[] - { unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8)) }; + byteBuffer = [unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8))]; } if (fallbackBuffer is null) @@ -1173,13 +1171,11 @@ internal sealed override unsafe int GetCharCount(byte* bytes, int count, Decoder byte[]? byteBuffer = null; if (bigEndian) { - byteBuffer = new byte[] - { unchecked((byte)(ch >> 8)), unchecked((byte)ch) }; + byteBuffer = [unchecked((byte)(ch >> 8)), unchecked((byte)ch)]; } else { - byteBuffer = new byte[] - { unchecked((byte)ch), unchecked((byte)(ch >> 8)) }; + byteBuffer = [unchecked((byte)ch), unchecked((byte)(ch >> 8))]; } if (fallbackBuffer is null) @@ -1211,13 +1207,11 @@ internal sealed override unsafe int GetCharCount(byte* bytes, int count, Decoder byte[]? byteBuffer = null; if (bigEndian) { - byteBuffer = new byte[] - { unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar) }; + byteBuffer = [unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar)]; } else { - byteBuffer = new byte[] - { unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8)) }; + byteBuffer = [unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8))]; } if (fallbackBuffer is null) @@ -1250,13 +1244,11 @@ internal sealed override unsafe int GetCharCount(byte* bytes, int count, Decoder byte[]? byteBuffer = null; if (bigEndian) { - byteBuffer = new byte[] - { unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar) }; + byteBuffer = [unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar)]; } else { - byteBuffer = new byte[] - { unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8)) }; + byteBuffer = [unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8))]; } if (fallbackBuffer is null) @@ -1287,7 +1279,7 @@ internal sealed override unsafe int GetCharCount(byte* bytes, int count, Decoder } // No hanging odd bytes allowed if must flush - charCount += fallbackBuffer.InternalFallback(new byte[] { unchecked((byte)lastByte) }, bytes); + charCount += fallbackBuffer.InternalFallback([unchecked((byte)lastByte)], bytes); lastByte = -1; } } @@ -1453,13 +1445,11 @@ internal sealed override unsafe int GetChars( byte[]? byteBuffer = null; if (bigEndian) { - byteBuffer = new byte[] - { unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar) }; + byteBuffer = [unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar)]; } else { - byteBuffer = new byte[] - { unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8)) }; + byteBuffer = [unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8))]; } if (fallbackBuffer is null) @@ -1504,13 +1494,11 @@ internal sealed override unsafe int GetChars( byte[]? byteBuffer = null; if (bigEndian) { - byteBuffer = new byte[] - { unchecked((byte)(ch >> 8)), unchecked((byte)ch) }; + byteBuffer = [unchecked((byte)(ch >> 8)), unchecked((byte)ch)]; } else { - byteBuffer = new byte[] - { unchecked((byte)ch), unchecked((byte)(ch >> 8)) }; + byteBuffer = [unchecked((byte)ch), unchecked((byte)(ch >> 8))]; } if (fallbackBuffer is null) @@ -1565,13 +1553,11 @@ internal sealed override unsafe int GetChars( byte[]? byteBuffer = null; if (bigEndian) { - byteBuffer = new byte[] - { unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar) }; + byteBuffer = [unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar)]; } else { - byteBuffer = new byte[] - { unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8)) }; + byteBuffer = [unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8))]; } if (fallbackBuffer is null) @@ -1629,13 +1615,11 @@ internal sealed override unsafe int GetChars( byte[]? byteBuffer = null; if (bigEndian) { - byteBuffer = new byte[] - { unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar) }; + byteBuffer = [unchecked((byte)(lastChar >> 8)), unchecked((byte)lastChar)]; } else { - byteBuffer = new byte[] - { unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8)) }; + byteBuffer = [unchecked((byte)lastChar), unchecked((byte)(lastChar >> 8))]; } if (fallbackBuffer is null) @@ -1688,7 +1672,7 @@ internal sealed override unsafe int GetChars( // No hanging odd bytes allowed if must flush charsForFallback = chars; // Avoid passing chars by reference to allow it to be en-registered - bool fallbackResult = fallbackBuffer.InternalFallback(new byte[] { unchecked((byte)lastByte) }, bytes, ref charsForFallback); + bool fallbackResult = fallbackBuffer.InternalFallback([unchecked((byte)lastByte)], bytes, ref charsForFallback); chars = charsForFallback; if (!fallbackResult) @@ -1745,9 +1729,9 @@ public override byte[] GetPreamble() // Note - we must allocate new byte[]'s here to prevent someone // from modifying a cached byte[]. if (bigEndian) - return new byte[2] { 0xfe, 0xff }; + return [0xfe, 0xff]; else - return new byte[2] { 0xff, 0xfe }; + return [0xff, 0xfe]; } return Array.Empty(); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs index c455235faf958..51e957eb18466 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs @@ -85,11 +85,11 @@ public void GetObjectData(SerializationInfo info, StreamingContext context) if (m_localValues == null || AsyncLocalValueMap.IsEmpty(m_localValues)) { -#pragma warning disable CA1825 // Avoid unnecessary zero-length array allocations +#pragma warning disable CA1825, IDE0300 // Avoid unnecessary zero-length array allocations return isFlowSuppressed ? (s_defaultFlowSuppressed ??= new ExecutionContext(AsyncLocalValueMap.Empty, new IAsyncLocal[0], isFlowSuppressed: true)) : null; // implies the default context -#pragma warning restore CA1825 +#pragma warning restore CA1825, IDE0300 } return new ExecutionContext(m_localValues, m_localChangeNotifications, isFlowSuppressed); @@ -515,7 +515,7 @@ internal static void SetLocalValue(IAsyncLocal local, object? newValue, bool nee } else if (newChangeNotifications == null) { - newChangeNotifications = new IAsyncLocal[1] { local }; + newChangeNotifications = [local]; } else { diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs index 6fc5ae0d00660..737420c8f06a3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @@ -6996,7 +6996,7 @@ internal static Task CreateUnwrapPromise(Task outerTask, bool { if (continuationObject is Action singleAction) { - return new Delegate[] { AsyncMethodBuilderCore.TryGetStateMachineForDebugger(singleAction) }; + return [AsyncMethodBuilderCore.TryGetStateMachineForDebugger(singleAction)]; } if (continuationObject is TaskContinuation taskContinuation) @@ -7015,7 +7015,7 @@ internal static Task CreateUnwrapPromise(Task outerTask, bool // the VS debugger is more interested in the continuation than the internal invoke() if (continuationObject is ITaskCompletionAction singleCompletionAction) { - return new Delegate[] { new Action(singleCompletionAction.Invoke) }; + return [new Action(singleCompletionAction.Invoke)]; } if (continuationObject is List continuationList) diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs index fac0bb9d4b25e..a99b3425f9b4d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskContinuation.cs @@ -357,7 +357,7 @@ internal override void Run(Task completedTask, bool canInlineContinuationTask) internal override Delegate[]? GetDelegateContinuationsForDebugger() => m_task is null ? null : m_task.m_action is null ? m_task.GetDelegateContinuationsForDebugger() : - new Delegate[] { m_task.m_action }; + [m_task.m_action]; } /// Task continuation for awaiting with a current synchronization context. @@ -824,7 +824,7 @@ internal static void UnsafeScheduleAction(Action action, Task? task) internal override Delegate[] GetDelegateContinuationsForDebugger() { Debug.Assert(m_action != null); - return new Delegate[] { AsyncMethodBuilderCore.TryGetStateMachineForDebugger(m_action) }; + return [AsyncMethodBuilderCore.TryGetStateMachineForDebugger(m_action)]; } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskScheduler.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskScheduler.cs index 30fc1e9958daa..73e2b8869ae23 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskScheduler.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskScheduler.cs @@ -490,7 +490,7 @@ internal static TaskScheduler[] GetTaskSchedulersForDebugger() if (s_activeTaskSchedulers == null) { // No schedulers were tracked. Just give back the default. - return new TaskScheduler[] { s_defaultTaskScheduler }; + return [s_defaultTaskScheduler]; } List schedulers = new List(); diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs index d870c60648c6a..3c1d958314ebb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs @@ -20,9 +20,9 @@ internal sealed partial class ThreadPoolWorkQueue { internal static class WorkStealingQueueList { -#pragma warning disable CA1825 // avoid the extra generic instantiation for Array.Empty(); this is the only place we'll ever create this array +#pragma warning disable CA1825, IDE0300 // avoid the extra generic instantiation for Array.Empty(); this is the only place we'll ever create this array private static WorkStealingQueue[] s_queues = new WorkStealingQueue[0]; -#pragma warning restore CA1825 +#pragma warning restore CA1825, IDE0300 public static WorkStealingQueue[] Queues => s_queues; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/WaitHandle.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/WaitHandle.cs index 7f593e204b942..4fd60e8bbee60 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/WaitHandle.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/WaitHandle.cs @@ -137,7 +137,7 @@ internal bool WaitOneNoCheck( if (context != null && context.IsWaitNotificationRequired()) { usedSyncContextWait = true; - waitResult = context.Wait(new[] { waitHandle.DangerousGetHandle() }, false, millisecondsTimeout); + waitResult = context.Wait([waitHandle.DangerousGetHandle()], false, millisecondsTimeout); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Win32.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Win32.cs index 20e22312d8677..957b88820edcf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Win32.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Win32.cs @@ -152,7 +152,7 @@ private TimeZoneInfo(in TIME_ZONE_INFORMATION zone, bool dstDisabled) AdjustmentRule? rule = CreateAdjustmentRuleFromTimeZoneInformation(regZone, DateTime.MinValue.Date, DateTime.MaxValue.Date, zone.Bias); if (rule != null) { - _adjustmentRules = new[] { rule }; + _adjustmentRules = [rule]; } } @@ -524,7 +524,7 @@ private static bool TryCreateAdjustmentRules(string id, in REG_TZI_FORMAT defaul defaultTimeZoneInformation, DateTime.MinValue.Date, DateTime.MaxValue.Date, defaultBaseUtcOffset); if (rule != null) { - rules = new[] { rule }; + rules = [rule]; } return true; } @@ -558,7 +558,7 @@ private static bool TryCreateAdjustmentRules(string id, in REG_TZI_FORMAT defaul AdjustmentRule? rule = CreateAdjustmentRuleFromTimeZoneInformation(dtzi, DateTime.MinValue.Date, DateTime.MaxValue.Date, defaultBaseUtcOffset); if (rule != null) { - rules = new[] { rule }; + rules = [rule]; } return true; }