تغییرات مهم مقایسهی رشتهها در NET 5.0.
نویسنده: وحید نصیری
تاریخ: ۱۳۹۹/۰۸/۲۴ ۱۳:۲۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
string s = "Hello\r\nworld!";
int idx = s.IndexOf("\n");
Console.WriteLine(idx);
int idx = s.IndexOf("\n", StringComparison.Ordinal); <ItemGroup> <RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" /> </ItemGroup>
System.String.Compare System.String.EndsWith System.String.IndexOf System.String.StartsWith System.String.ToLower System.String.ToLowerInvariant System.String.ToUpper System.String.ToUpperInvariant System.Globalization.TextInfo (most members) System.Globalization.CompareInfo (most members) System.Array.Sort (when sorting arrays of strings) System.Collections.Generic.List<T>.Sort() (when the list elements are strings) System.Collections.Generic.SortedDictionary<TKey,TValue> (when the keys are strings) System.Collections.Generic.SortedList<TKey,TValue> (when the keys are strings) System.Collections.Generic.SortedSet<T> (when the set contains strings)
API Default behavior Remarks string.Compare CurrentCulture
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>
</Project> [*.cs] # CA1304: Specify CultureInfo # Help link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1304 dotnet_diagnostic.CA1304.severity = error # CA1305: Specify IFormatProvider # Help link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305 dotnet_diagnostic.CA1305.severity = error # CA1307: Specify StringComparison for clarity # Help link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1307 dotnet_diagnostic.CA1307.severity = error # CA1308: Normalize strings to uppercase # Help link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1308 dotnet_diagnostic.CA1308.severity = error # CA1309: Use ordinal string comparison # Help link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1309 dotnet_diagnostic.CA1309.severity = error # CA1310: Specify StringComparison for correctness # Help link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1310 dotnet_diagnostic.CA1310.severity = error # CA1311: Specify a culture or use an invariant version # Help link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1311 dotnet_diagnostic.CA1311.severity = error # CA1820: Test for empty strings using string length # Help link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1820 dotnet_diagnostic.CA1820.severity = error # CA1834: Consider using 'StringBuilder.Append(char)' when applicable # Help link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1834 dotnet_diagnostic.CA1834.severity = error # CA1858: Use 'StartsWith' instead of 'IndexOf' # Help link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1858 dotnet_diagnostic.CA1858.severity = error # CA2249: Consider using 'string.Contains' instead of 'string.IndexOf' # Help link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2249 dotnet_diagnostic.CA2249.severity = error # CA2251: Use 'string.Equals' # Help link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2251 dotnet_diagnostic.CA2251.severity = error