diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection/src/CallSiteJsonFormatter.cs b/src/libraries/Microsoft.Extensions.DependencyInjection/src/CallSiteJsonFormatter.cs index a2b3d5f095244c..eb26ebb7cfa7fb 100644 --- a/src/libraries/Microsoft.Extensions.DependencyInjection/src/CallSiteJsonFormatter.cs +++ b/src/libraries/Microsoft.Extensions.DependencyInjection/src/CallSiteJsonFormatter.cs @@ -183,7 +183,7 @@ public void WriteProperty(string name, object value) } else { - Builder.AppendFormat( "null"); + Builder.Append( "null"); } } diff --git a/src/libraries/Microsoft.Win32.Primitives/src/System/ComponentModel/Win32Exception.cs b/src/libraries/Microsoft.Win32.Primitives/src/System/ComponentModel/Win32Exception.cs index e3159637dc7eac..0fde7ca4f87b3e 100644 --- a/src/libraries/Microsoft.Win32.Primitives/src/System/ComponentModel/Win32Exception.cs +++ b/src/libraries/Microsoft.Win32.Primitives/src/System/ComponentModel/Win32Exception.cs @@ -91,11 +91,11 @@ public override string ToString() : NativeErrorCode.ToString(CultureInfo.InvariantCulture); if (HResult == E_FAIL) { - s.AppendFormat($" ({nativeErrorString})"); + s.Append($" ({nativeErrorString})"); } else { - s.AppendFormat($" ({HResult:X8}, {nativeErrorString})"); + s.Append($" ({HResult:X8}, {nativeErrorString})"); } if (!(string.IsNullOrEmpty(message))) diff --git a/src/libraries/System.Data.Common/src/System/Data/DataViewManager.cs b/src/libraries/System.Data.Common/src/System/Data/DataViewManager.cs index 02da21f71f003f..80cc255a5e4a3a 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataViewManager.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataViewManager.cs @@ -5,6 +5,7 @@ using System.Collections; using System.Diagnostics.CodeAnalysis; using System.IO; +using System.Globalization; using System.Text; using System.Xml; @@ -92,7 +93,7 @@ public string DataViewSettingCollectionString foreach (DataTable dt in _dataSet.Tables) { DataViewSetting ds = _dataViewSettingsCollection[dt]; - builder.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "<{0} Sort=\"{1}\" RowFilter=\"{2}\" RowStateFilter=\"{3}\"/>", dt.EncodedTableName, ds.Sort, ds.RowFilter, ds.RowStateFilter); + builder.Append(CultureInfo.InvariantCulture, $"<{dt.EncodedTableName} Sort=\"{ds.Sort}\" RowFilter=\"{ds.RowFilter}\" RowStateFilter=\"{ds.RowStateFilter}\"/>"); } builder.Append(""); return builder.ToString(); diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs index b061bf43d54afa..223972940e800c 100644 --- a/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs +++ b/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs @@ -1157,12 +1157,11 @@ private static string GetAssociationDetails() sb.AppendLine("------------------------------"); string open = GetAssociationString(0, 1 /* ASSOCSTR_COMMAND */, ".txt", "open"); - sb.AppendFormat("Open command: {0}", open); - sb.AppendLine(); + sb.AppendLine($"Open command: {open}"); string progId = GetAssociationString(0, 20 /* ASSOCSTR_PROGID */, ".txt", null); - sb.AppendFormat("ProgID: {0}", progId); - sb.AppendLine(); + sb.AppendLine($"ProgID: {progId}"); + return sb.ToString(); } diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs index cbc80bebc8d96b..5c0a9b554b5335 100644 --- a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs +++ b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs @@ -1174,10 +1174,10 @@ string PrintProcesses(Process currentProcess) StringBuilder builder = new StringBuilder(); foreach (Process process in Process.GetProcesses()) { - builder.AppendFormat("Pid: '{0}' Name: '{1}'", process.Id, process.ProcessName); + builder.Append($"Pid: '{process.Id}' Name: '{process.ProcessName}'"); try { - builder.AppendFormat(" Main module: '{0}'", process.MainModule.FileName); + builder.Append($" Main module: '{process.MainModule.FileName}'"); } catch { @@ -1186,7 +1186,7 @@ string PrintProcesses(Process currentProcess) builder.AppendLine(); } - builder.AppendFormat("Current process id: {0} Process name: '{1}'", currentProcess.Id, currentProcess.ProcessName); + builder.Append($"Current process id: {currentProcess.Id} Process name: '{currentProcess.ProcessName}'"); return builder.ToString(); } } diff --git a/src/libraries/System.Globalization/tests/System/Globalization/GraphemeBreakTest.cs b/src/libraries/System.Globalization/tests/System/Globalization/GraphemeBreakTest.cs index 678f61b6ea82aa..a79b3eef2bae61 100644 --- a/src/libraries/System.Globalization/tests/System/Globalization/GraphemeBreakTest.cs +++ b/src/libraries/System.Globalization/tests/System/Globalization/GraphemeBreakTest.cs @@ -222,7 +222,7 @@ private static string PrintCodePointsForDebug(IEnumerable input) if (!char.IsHighSurrogate(thisChar) || !enumerator.MoveNext()) { // not a high surrogate, or a high surrogate at the end of the sequence - it goes as-is - sb.AppendFormat(CultureInfo.InvariantCulture, "{0:X4} ", (uint)thisChar); + sb.Append($"{(uint)thisChar:X4} "); } else { @@ -230,13 +230,13 @@ private static string PrintCodePointsForDebug(IEnumerable input) if (!char.IsLowSurrogate(secondChar)) { // previous char was a standalone high surrogate char - send it as-is - sb.AppendFormat(CultureInfo.InvariantCulture, "{0:X4} ", (uint)thisChar); + sb.Append($"{(uint)thisChar:X4} "); goto SawStandaloneChar; } else { // surrogate pair - extract supplementary code point - sb.AppendFormat(CultureInfo.InvariantCulture, "{0:X4} ", (uint)char.ConvertToUtf32(thisChar, secondChar)); + sb.Append($"{(uint)char.ConvertToUtf32(thisChar, secondChar):X4} "); } } } diff --git a/src/libraries/System.Linq.Expressions/tests/ILReader/FormatProvider.cs b/src/libraries/System.Linq.Expressions/tests/ILReader/FormatProvider.cs index fb9b9d02b7a3d1..76479d709f6454 100644 --- a/src/libraries/System.Linq.Expressions/tests/ILReader/FormatProvider.cs +++ b/src/libraries/System.Linq.Expressions/tests/ILReader/FormatProvider.cs @@ -37,11 +37,11 @@ public virtual string MultipleLabels(int[] offsets) int length = offsets.Length; for (int i = 0; i < length; i++) { - if (i == 0) sb.AppendFormat("("); - else sb.AppendFormat(", "); + if (i == 0) sb.Append('('); + else sb.Append(", "); sb.Append(Label(offsets[i])); } - sb.AppendFormat(")"); + sb.Append(')'); return sb.ToString(); } @@ -57,7 +57,7 @@ public virtual string EscapedString(string str) else if (ch == '\r') sb.Append("\\r"); else if (ch == '\"') sb.Append("\\\""); else if (ch == '\\') sb.Append("\\"); - else if (ch < 0x20 || ch >= 0x7f) sb.AppendFormat("\\u{0:x4}", (int)ch); + else if (ch < 0x20 || ch >= 0x7f) sb.Append($"\\u{(int)ch:x4}"); else sb.Append(ch); } return "\"" + sb.ToString() + "\""; @@ -69,11 +69,11 @@ public virtual string SigByteArrayToString(byte[] sig) int length = sig.Length; for (int i = 0; i < length; i++) { - if (i == 0) sb.AppendFormat("SIG ["); - else sb.AppendFormat(" "); + if (i == 0) sb.Append("SIG ["); + else sb.Append(' '); sb.Append(Int8ToHex(sig[i])); } - sb.AppendFormat("]"); + sb.Append(']'); return sb.ToString(); } } 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 50d873d90b5e90..0e215f478dde63 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/StackTrace.cs @@ -225,7 +225,7 @@ internal void ToString(TraceFormat traceFormat, StringBuilder sb) else sb.AppendLine(); - sb.AppendFormat(CultureInfo.InvariantCulture, " {0} ", word_At); + sb.Append(" ").Append(word_At).Append(' '); bool isAsync = false; Type? declaringType = mb.DeclaringType; 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 593a9ab1e4fb01..e72e7885566401 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs @@ -811,16 +811,16 @@ private static void FormatCustomizedTimeZone(DateTime dateTime, TimeSpan offset, if (tokenLen <= 1) { // 'z' format e.g "-7" - result.AppendFormat(CultureInfo.InvariantCulture, "{0:0}", offset.Hours); + result.Append(CultureInfo.InvariantCulture, $"{offset.Hours:0}"); } else { // 'zz' or longer format e.g "-07" - result.AppendFormat(CultureInfo.InvariantCulture, "{0:00}", offset.Hours); + result.Append(CultureInfo.InvariantCulture, $"{offset.Hours:00}"); if (tokenLen >= 3) { // 'zzz*' or longer format e.g "-07:30" - result.AppendFormat(CultureInfo.InvariantCulture, ":{0:00}", offset.Minutes); + result.Append(CultureInfo.InvariantCulture, $":{offset.Minutes:00}"); } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/SortKey.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/SortKey.cs index db67dce64c5fde..a98b7b880d1fda 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/SortKey.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/SortKey.cs @@ -6,9 +6,7 @@ namespace System.Globalization { - /// - /// This class implements a set of methods for retrieving - /// + /// Represents the result of mapping a string to its sort key. public sealed partial class SortKey { private readonly CompareInfo _compareInfo; @@ -67,20 +65,11 @@ public static int Compare(SortKey sortkey1, SortKey sortkey2) return new ReadOnlySpan(key1Data).SequenceCompareTo(key2Data); } - public override bool Equals([NotNullWhen(true)] object? value) - { - return value is SortKey other - && new ReadOnlySpan(_keyData).SequenceEqual(other._keyData); - } + public override bool Equals([NotNullWhen(true)] object? value) => + value is SortKey other && new ReadOnlySpan(_keyData).SequenceEqual(other._keyData); - public override int GetHashCode() - { - return _compareInfo.GetHashCode(_string, _options); - } + public override int GetHashCode() => _compareInfo.GetHashCode(_string, _options); - public override string ToString() - { - return "SortKey - " + _compareInfo.Name + ", " + _options + ", " + _string; - } + public override string ToString() => $"SortKey - {_compareInfo.Name}, {_options}, {_string}"; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/LocalVariableInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/LocalVariableInfo.cs index 9b662e713e98b9..2e1bf6d2c9959f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/LocalVariableInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/LocalVariableInfo.cs @@ -11,14 +11,8 @@ public class LocalVariableInfo public virtual int LocalIndex => 0; public virtual bool IsPinned => false; protected LocalVariableInfo() { } - public override string ToString() - { - string toString = LocalType.ToString() + " (" + LocalIndex + ")"; - - if (IsPinned) - toString += " (pinned)"; - - return toString; - } + public override string ToString() => IsPinned ? + $"{LocalType} ({LocalIndex}) (pinned)" : + $"{LocalType} ({LocalIndex})"; } } 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 77b4a681354c1c..ad98312fadd85b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Resources/FileBasedResourceGroveler.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Resources/FileBasedResourceGroveler.cs @@ -49,7 +49,8 @@ public FileBasedResourceGroveler(ResourceManager.ResourceManagerMediator mediato { // We really don't think this should happen - we always // expect the neutral locale's resources to be present. - throw new MissingManifestResourceException(SR.MissingManifestResource_NoNeutralDisk + Environment.NewLineConst + "baseName: " + _mediator.BaseNameField + " locationInfo: " + (_mediator.LocationInfo == null ? "" : _mediator.LocationInfo.FullName) + " fileName: " + _mediator.GetResourceFileName(culture)); + string? locationInfo = _mediator.LocationInfo == null ? "" : _mediator.LocationInfo.FullName; + throw new MissingManifestResourceException($"{SR.MissingManifestResource_NoNeutralDisk}{Environment.NewLineConst}baseName: {_mediator.BaseNameField} locationInfo: {locationInfo} fileName: {_mediator.GetResourceFileName(culture)}"); } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs index 2a5a3c1da07fb6..b05714fd92ccad 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs @@ -259,7 +259,7 @@ public event Action? Unloading public string? Name => _name; - public override string ToString() => "\"" + Name + "\" " + GetType().ToString() + " #" + _id; + public override string ToString() => $"\"{Name}\" {GetType()} #{_id}"; public static IEnumerable All { diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs index 16f880e8591c95..7cff5468f96394 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs @@ -52,22 +52,9 @@ public string FullName { if (_fullName == null) { - if (string.IsNullOrEmpty(Profile)) - { - _fullName = - Identifier + - ComponentSeparator + VersionKey + KeyValueSeparator + VersionValuePrefix + - Version.ToString(); - } - else - { - _fullName = - Identifier + - ComponentSeparator + VersionKey + KeyValueSeparator + VersionValuePrefix + - Version.ToString() + - ComponentSeparator + ProfileKey + KeyValueSeparator + - Profile; - } + _fullName = string.IsNullOrEmpty(Profile) ? + $"{Identifier}{ComponentSeparator + VersionKey + KeyValueSeparator + VersionValuePrefix}{Version}" : + $"{Identifier}{ComponentSeparator + VersionKey + KeyValueSeparator + VersionValuePrefix}{Version}{ComponentSeparator + ProfileKey + KeyValueSeparator}{Profile}"; } Debug.Assert(_fullName != null); diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/DecoderFallback.cs b/src/libraries/System.Private.CoreLib/src/System/Text/DecoderFallback.cs index da8d1236f4479e..a584f2fd65dbd6 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/DecoderFallback.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/DecoderFallback.cs @@ -301,7 +301,7 @@ internal static void ThrowLastBytesRecursive(byte[] bytesUnknown) { if (strBytes.Length > 0) strBytes.Append(' '); - strBytes.AppendFormat(CultureInfo.InvariantCulture, "\\x{0:X2}", bytesUnknown[i]); + strBytes.Append($"\\x{bytesUnknown[i]:X2}"); } // In case the string's really long if (i == 20) diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBaseWriter.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBaseWriter.cs index 0b29ab21bfe300..fe410e17c489f2 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBaseWriter.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlBaseWriter.cs @@ -1769,7 +1769,7 @@ private string GeneratePrefix(string ns, XmlDictionaryString? xNs) while (true) { int prefixId = _elements![_depth].PrefixId++; - prefix = string.Concat("d", _depth.ToString(CultureInfo.InvariantCulture), "p", prefixId.ToString(CultureInfo.InvariantCulture)); + prefix = string.Create(CultureInfo.InvariantCulture, $"d{_depth}p{prefixId}"); if (_nsMgr.LookupNamespace(prefix) == null) { diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlDictionaryWriter.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlDictionaryWriter.cs index 9c3b659ae760de..183029efc0d582 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlDictionaryWriter.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlDictionaryWriter.cs @@ -122,8 +122,7 @@ public virtual void WriteXmlnsAttribute(string? prefix, string namespaceUri) { if (LookupPrefix(namespaceUri) != null) return; -#pragma warning suppress 56506 // Microsoft, namespaceUri is already checked - prefix = namespaceUri.Length == 0 ? string.Empty : string.Concat("d", namespaceUri.Length.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); + prefix = namespaceUri.Length == 0 ? string.Empty : $"d{namespaceUri.Length}"; } WriteAttributeString("xmlns", prefix, null, namespaceUri); } diff --git a/src/libraries/System.Private.Uri/src/System/Uri.cs b/src/libraries/System.Private.Uri/src/System/Uri.cs index dc687676f03f36..2c8eda44112465 100644 --- a/src/libraries/System.Private.Uri/src/System/Uri.cs +++ b/src/libraries/System.Private.Uri/src/System/Uri.cs @@ -4864,12 +4864,10 @@ private static string CombineUri(Uri basePart, string relativePart, UriFormat ur return basePart.Scheme + ':' + relativePart; } - // Got absolute relative path, and the base is nor FILE nor a DOS path (checked at the method start) + // Got absolute relative path, and the base is not FILE nor a DOS path (checked at the method start) if (basePart.HostType == Flags.IPv6HostType) { - left = basePart.GetParts(UriComponents.Scheme | UriComponents.UserInfo, uriFormat) - + '[' + basePart.DnsSafeHost + ']' - + basePart.GetParts(UriComponents.KeepDelimiter | UriComponents.Port, uriFormat); + left = $"{basePart.GetParts(UriComponents.Scheme | UriComponents.UserInfo, uriFormat)}[{basePart.DnsSafeHost}]{basePart.GetParts(UriComponents.KeepDelimiter | UriComponents.Port, uriFormat)}"; } else { diff --git a/src/libraries/System.Private.Xml.Linq/tests/xNodeReader/ReadBinHex.cs b/src/libraries/System.Private.Xml.Linq/tests/xNodeReader/ReadBinHex.cs index 9cac33d3f1fdba..dcccfdd02fccae 100644 --- a/src/libraries/System.Private.Xml.Linq/tests/xNodeReader/ReadBinHex.cs +++ b/src/libraries/System.Private.Xml.Linq/tests/xNodeReader/ReadBinHex.cs @@ -447,7 +447,7 @@ public void TestTextReadBinHex_24() bytes = DataReader.ReadContentAsBinHex(bbb, 0, bbb.Length); for (int i = 0; i < bytes; i++) { - output.AppendFormat(bbb[i].ToString()); + output.Append(bbb[i]); } } @@ -866,7 +866,7 @@ public void TestTextReadBinHex_24() bytes = DataReader.ReadElementContentAsBinHex(bbb, 0, bbb.Length); for (int i = 0; i < bytes; i++) { - output.AppendFormat(bbb[i].ToString()); + output.Append(bbb[i]); } } if (TestLog.Compare(output.ToString().Length, 1735, "Expected Length : 1735")) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeInfoAtom.cs b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeInfoAtom.cs index 9afbc4f400bd7f..298001f4db95da 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeInfoAtom.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeInfoAtom.cs @@ -499,7 +499,7 @@ public override string ToString() for (int i = 0; i < _hashTable.Length; i++) { - bldr.AppendFormat("{0,4}: ", i); + bldr.Append($"{i,4}: "); infoAtom = _hashTable[i]; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriter.cs index f4ff03f0bf01d8..583bd82b6e07f9 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/XmlWellFormedWriter.cs @@ -2109,7 +2109,7 @@ private static string GetStateName(State state) private string GeneratePrefix() { - string genPrefix = "p" + (_nsTop - 2).ToString("d", CultureInfo.InvariantCulture); + string genPrefix = string.Create(CultureInfo.InvariantCulture, $"p{_nsTop - 2:d}"); if (LookupNamespace(genPrefix) == null) { return genPrefix; @@ -2119,7 +2119,7 @@ private string GeneratePrefix() string s; do { - s = string.Concat(genPrefix, i.ToString(CultureInfo.InvariantCulture)); + s = string.Create(CultureInfo.InvariantCulture, $"{genPrefix}{i}"); i++; } while (LookupNamespace(s) != null); return s; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/ContentValidator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/ContentValidator.cs index 0a4ad3d346eed3..876fcb6abc6964 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/ContentValidator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/ContentValidator.cs @@ -1569,7 +1569,7 @@ private void Dump(StringBuilder bb, BitSet[] followpos, int[][] transitionTable) } else { - bb.AppendFormat(" {0:000} ", transitionTable[i][j]); + bb.Append($" {transitionTable[i][j]:000} "); } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryRuntime.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryRuntime.cs index 4bdaf545111250..4415fa1b457f9e 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryRuntime.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlQueryRuntime.cs @@ -884,7 +884,7 @@ public IList DocOrderDistinct(IList seq) /// public string GenerateId(XPathNavigator navigator) { - return string.Concat("ID", _docOrderCmp.GetDocumentIndex(navigator).ToString(CultureInfo.InvariantCulture), navigator.UniqueId); + return string.Create(CultureInfo.InvariantCulture, $"ID{_docOrderCmp.GetDocumentIndex(navigator)}{navigator.UniqueId}"); } diff --git a/src/libraries/System.Private.Xml/tests/XmlReaderLib/ReadBase64.cs b/src/libraries/System.Private.Xml/tests/XmlReaderLib/ReadBase64.cs index a3a7160f57b123..5d7e9cc93812b1 100644 --- a/src/libraries/System.Private.Xml/tests/XmlReaderLib/ReadBase64.cs +++ b/src/libraries/System.Private.Xml/tests/XmlReaderLib/ReadBase64.cs @@ -1076,7 +1076,7 @@ public int TestReadBase64ReadsTheContent() for (int i = 0; i < bytes; i++) { CError.Write(bbb[i].ToString()); - output.AppendFormat(bbb[i].ToString()); + output.Append(bbb[i]); } } CError.WriteLine(); diff --git a/src/libraries/System.Private.Xml/tests/XmlReaderLib/ReadBinHex.cs b/src/libraries/System.Private.Xml/tests/XmlReaderLib/ReadBinHex.cs index a490ec0a8c203c..f764af73700a6e 100644 --- a/src/libraries/System.Private.Xml/tests/XmlReaderLib/ReadBinHex.cs +++ b/src/libraries/System.Private.Xml/tests/XmlReaderLib/ReadBinHex.cs @@ -457,7 +457,7 @@ public int TestTextReadBinHex_24() for (int i = 0; i < bytes; i++) { CError.Write(bbb[i].ToString()); - output.AppendFormat(bbb[i].ToString()); + output.Append(bbb[i]); } } @@ -880,7 +880,7 @@ public int TestTextReadBinHex_24() for (int i = 0; i < bytes; i++) { CError.Write(bbb[i].ToString()); - output.AppendFormat(bbb[i].ToString()); + output.Append(bbb[i]); } } diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/DescriptionNameTests.cs b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/DescriptionNameTests.cs index 4568724fc9947f..c0069896dc49a9 100644 --- a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/DescriptionNameTests.cs +++ b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/DescriptionNameTests.cs @@ -70,7 +70,7 @@ public void DumpRuntimeInformationToConsole() { var sb = new StringBuilder(); sb.AppendLine("### PROCESS INFORMATION:"); - sb.AppendFormat($"###\tArchitecture: {RuntimeInformation.ProcessArchitecture.ToString()}").AppendLine(); + sb.AppendLine($"###\tArchitecture: {RuntimeInformation.ProcessArchitecture}"); foreach (string prop in new string[] { nameof(p.BasePriority), diff --git a/src/libraries/System.Runtime.Serialization.Xml/tests/Canonicalization/XmlCanonicalizationTest.cs b/src/libraries/System.Runtime.Serialization.Xml/tests/Canonicalization/XmlCanonicalizationTest.cs index cb61cfdaa40c8d..a04a990f0e5d41 100644 --- a/src/libraries/System.Runtime.Serialization.Xml/tests/Canonicalization/XmlCanonicalizationTest.cs +++ b/src/libraries/System.Runtime.Serialization.Xml/tests/Canonicalization/XmlCanonicalizationTest.cs @@ -320,12 +320,11 @@ public static void ReaderWriter_C14N_DifferentReadersWriters() string value = "attrValue" + i; if (prefix == null) { - sb.AppendFormat(" {0}=\"{1}\"", localName, value); + sb.Append($" {localName}=\"{value}\""); } else { - sb.AppendFormat(" {0}:{1}=\"{2}\" xmlns:{0}=\"{3}\"", - prefix, localName, value, namespaceUri); + sb.Append($" {prefix}:{localName}=\"{2}\" xmlns:{value}=\"{namespaceUri}\""); } } sb.Append(">Hello world"); diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/tests/ChainTests.cs b/src/libraries/System.Security.Cryptography.X509Certificates/tests/ChainTests.cs index 135eed056df9d1..bf0b9e230a169b 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/tests/ChainTests.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/tests/ChainTests.cs @@ -741,7 +741,7 @@ public static void BuildChain_MicrosoftDotCom_WithRootCertInUserAndSystemRootCer StringBuilder builder = new StringBuilder(); foreach (var status in chainValidator.ChainStatus) { - builder.AppendFormat("{0} {1}{2}", status.Status, status.StatusInformation, Environment.NewLine); + builder.AppendLine($"{status.Status} {status.StatusInformation}"); } Assert.True(chainBuildResult, diff --git a/src/libraries/System.Text.Encodings.Web/tests/TextEncoderBatteryTests.cs b/src/libraries/System.Text.Encodings.Web/tests/TextEncoderBatteryTests.cs index 5a8f3e6a2df4d0..f2cc020d355735 100644 --- a/src/libraries/System.Text.Encodings.Web/tests/TextEncoderBatteryTests.cs +++ b/src/libraries/System.Text.Encodings.Web/tests/TextEncoderBatteryTests.cs @@ -66,7 +66,7 @@ public static IEnumerable TestData() } else { - sbOutput.AppendFormat(CultureInfo.InvariantCulture, "[{0:X4}]", i); + sbOutput.Append($"[{i:X4}]"); } } diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCode.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCode.cs index e76e3ea160aafc..ffcc7a6e07450d 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCode.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCode.cs @@ -292,7 +292,7 @@ public string OpcodeDescription(int offset) var sb = new StringBuilder(); int opcode = Codes[offset]; - sb.AppendFormat("{0:D6} ", offset); + sb.Append($"{offset:D6} "); sb.Append(OpcodeBacktracks(opcode & Mask) ? '*' : ' '); sb.Append(OperatorDescription(opcode)); sb.Append(Indent()); diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs index b9b6e791ed5720..81f5ca065f0e1c 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs @@ -5367,7 +5367,7 @@ private void DumpBacktracking() var sb = new StringBuilder(); if (_backpos > 0) { - sb.AppendFormat("{0:D6} ", _backpos); + sb.Append($"{_backpos:D6} "); } else { diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexNode.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexNode.cs index bd55727af62a97..460496361d387b 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexNode.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexNode.cs @@ -1161,11 +1161,11 @@ private void ReduceConcatenationWithAdjacentStrings() if ((optionsAt & RegexOptions.RightToLeft) == 0) { - prev.Str += (at.Type == One) ? at.Ch.ToString() : at.Str; + prev.Str = (at.Type == One) ? $"{prev.Str}{at.Ch}" : prev.Str + at.Str; } else { - prev.Str = (at.Type == One) ? at.Ch.ToString() + prev.Str : at.Str + prev.Str; + prev.Str = (at.Type == One) ? $"{at.Ch}{prev.Str}" : at.Str + prev.Str; } } else if (at.Type == Empty) diff --git a/src/libraries/System.Threading.Timer/tests/TimerFiringTests.cs b/src/libraries/System.Threading.Timer/tests/TimerFiringTests.cs index 785fc4cc6b18bd..c01c8b4e644196 100644 --- a/src/libraries/System.Threading.Timer/tests/TimerFiringTests.cs +++ b/src/libraries/System.Threading.Timer/tests/TimerFiringTests.cs @@ -339,12 +339,11 @@ orderby groupedByDueTime.Key select groupedByDueTime; var sb = new StringBuilder(); - sb.AppendFormat("{0}% out of {1} timer firings were off by more than {2}ms", - percOutOfRange, totalTimers, MillisecondsPadding); + sb.Append($"{percOutOfRange}% out of {totalTimers} timer firings were off by more than {MillisecondsPadding}ms"); foreach (IGrouping> result in results) { sb.AppendLine(); - sb.AppendFormat("Expected: {0}, Actuals: {1}", result.Key, string.Join(", ", result.Select(k => k.Value))); + sb.Append($"Expected: {result.Key}, Actuals: {string.Join(", ", result.Select(k => k.Value))}"); } Assert.True(false, sb.ToString()); diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/InternalTransaction.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/InternalTransaction.cs index b16ec9e1a17720..e4633703561cfc 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/InternalTransaction.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/InternalTransaction.cs @@ -168,7 +168,7 @@ internal DistributedTransaction? PromotedTransaction private static string? s_instanceIdentifier; internal static string InstanceIdentifier => - LazyInitializer.EnsureInitialized(ref s_instanceIdentifier, ref s_classSyncObject, () => Guid.NewGuid().ToString() + ":"); + LazyInitializer.EnsureInitialized(ref s_instanceIdentifier, ref s_classSyncObject, () => $"{Guid.NewGuid()}:"); // Double-checked locking pattern requires volatile for read/write synchronization private volatile bool _traceIdentifierInited; diff --git a/src/libraries/System.Web.HttpUtility/src/System/Web/HttpUtility.cs b/src/libraries/System.Web.HttpUtility/src/System/Web/HttpUtility.cs index d991cc61d3f109..365b6c6bcfb25c 100644 --- a/src/libraries/System.Web.HttpUtility/src/System/Web/HttpUtility.cs +++ b/src/libraries/System.Web.HttpUtility/src/System/Web/HttpUtility.cs @@ -3,7 +3,7 @@ // Authors: // Patrik Torstensson (Patrik.Torstensson@labs2.com) -// Wictor Wilén (decode/encode functions) (wictor@ibizkit.se) +// Wictor WilĂŠn (decode/encode functions) (wictor@ibizkit.se) // Tim Coleman (tim@timcoleman.com) // Gonzalo Paniagua Javier (gonzalo@ximian.com) // @@ -59,19 +59,17 @@ public override string ToString() string?[] keys = AllKeys; for (int i = 0; i < count; i++) { - string[]? values = GetValues(keys[i]); + string? key = keys[i]; + string[]? values = GetValues(key); if (values != null) { foreach (string value in values) { - if (string.IsNullOrEmpty(keys[i])) + if (!string.IsNullOrEmpty(key)) { - sb.Append(UrlEncode(value)).Append('&'); - } - else - { - sb.AppendFormat($"{keys[i]}={UrlEncode(value)}&"); + sb.Append(key).Append('='); } + sb.Append(UrlEncode(value)).Append('&'); } } }