Skip to content

Commit 51c337b

Browse files
authored
Update example to use const (#48262)
* update example * add a new example
1 parent a3d6a08 commit 51c337b

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

docs/csharp/misc/cs0131.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,34 @@ public class MyClass
3333
}
3434
public static void Main() { }
3535
}
36-
```
36+
```
37+
38+
## Example 2
39+
40+
The following sample generates CS0131 when assigning to a constant field.
3741

38-
## Example 2
42+
```csharp
43+
// CS0131b.cs
44+
public class B
45+
{
46+
public static int Main()
47+
{
48+
const int j = 0;
49+
j = 1; // CS0131
50+
// try the following lines instead
51+
// int j = 0;
52+
// j = 1;
53+
return j;
54+
}
55+
}
56+
```
57+
58+
## Example 3
3959

4060
This error can also occur if you attempt to perform arithmetic operations on the left hand side of an assignment operator, as in the following example.
4161

4262
```csharp
43-
// CS0131b.cs
63+
// CS0131c.cs
4464
public class C
4565
{
4666
public static int Main()

0 commit comments

Comments
 (0)