This style rule was removed and converted to a Visual Studio refactoring in Visual Studio 2022. For information about the refactoring, see Convert anonymous type to tuple.
Property
Value
Rule ID
IDE0050
Title
Convert anonymous type to tuple
Category
Style
Subcategory
Language rules (expression-level preferences)
Applicable languages
C# and Visual Basic
Overview
This rule recommends use of tuples over anonymous types, when the anonymous type has two or more fields.
Options
This rule has no associated code-style options.
Example
C#
// Code with violationsvar t1 = new { a = 1, b = 2 };
// Fixed codevar t1 = (a: 1, b: 2);
' Code with violations
Dim t1 = New With { .a = 1, .b = 2 }
' Fixed code
Dim t1 = (a:=1, b:=2)
Suppress a warning
If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
C#
#pragmawarning disable IDE0050// The code that's violating the rule is on this line.#pragmawarning restore IDE0050
To disable the rule for a file, folder, or project, set its severity to none in the configuration file.
Vir za to vsebino najdete v storitvi GitHub, kjer lahko tudi ustvarite in pregledate težave in zahtevke za uveljavitev sprememb. Če želite več informacij, glejte naš vodnik za sodelavce.
Povratne informacije o izdelku .NET
.NET je odprtokodni projekt. Izberite povezavo za pošiljanje povratnih informacij: