File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
docs/fundamentals/code-analysis/quality-rules
snippets/csharp/all-rules Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ helpviewer_keywords:
1010 - " InitializeValueTypeStaticFieldsInline"
1111author : gewarren
1212ms.author : gewarren
13+ dev_langs :
14+ - CSharp
1315---
1416# CA2207: Initialize value type static fields inline
1517
@@ -35,6 +37,10 @@ If all static data is initialized inline and no explicit static constructor is d
3537
3638To fix a violation of this rule initialize all static data when it is declared and remove the static constructor.
3739
40+ ## Example
41+
42+ :::code language="csharp" source="snippets/csharp/all-rules/ca2207.cs" id="snippet1":::
43+
3844## When to suppress warnings
3945
4046Do not suppress a warning from this rule.
Original file line number Diff line number Diff line change 1+ namespace ca2207
2+ {
3+ //<snippet1>
4+ // This struct violates the rule.
5+ struct BadStruct
6+ {
7+ private static readonly int s_first ;
8+ private static readonly int s_second ;
9+
10+ static BadStruct ( )
11+ {
12+ s_first = 1 ;
13+ s_second = 2 ;
14+ }
15+
16+ // ...
17+ }
18+
19+ // This struct satisfies the rule.
20+ struct GoodStruct
21+ {
22+ private static readonly int s_first = 1 ;
23+ private static readonly int s_second = 2 ;
24+
25+ // ...
26+ }
27+ //</snippet1>
28+ }
You can’t perform that action at this time.
0 commit comments