Skip to content

Commit 01b1bd7

Browse files
committed
Fix build warnings
Update code samples for the template in use to remove nullable warnings. I did this as we plan to have nullable annotations on by default in this version of the spec.
1 parent 56ec57e commit 01b1bd7

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

standard/classes.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ All members of a generic class can use type parameters from any enclosing class,
878878
> class C<V>
879879
> {
880880
> public V f1;
881-
> public C<V> f2 = null;
881+
> public C<V> f2 = null!;
882882
>
883883
> public C(V x)
884884
> {
@@ -2390,7 +2390,7 @@ When performing overload resolution, a method with a parameter array might be ap
23902390
> ```csharp
23912391
> class Test
23922392
> {
2393-
> static void F(params string[] array) =>
2393+
> static void F(params string?[]? array) =>
23942394
> Console.WriteLine(array == null);
23952395
>
23962396
> static void Main()
@@ -5136,7 +5136,7 @@ Finalizers are invoked automatically, and cannot be invoked explicitly. An insta
51365136
> {
51375137
> static void Main()
51385138
> {
5139-
> B b = new B();
5139+
> B? b = new B();
51405140
> b = null;
51415141
> GC.Collect();
51425142
> GC.WaitForPendingFinalizers();

standard/delegates.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,22 +291,22 @@ Attempting to invoke a delegate instance whose value is `null` results in an exc
291291
> cd1(-1); // call M1
292292
> D cd2 = new D(C.M2);
293293
> cd2(-2); // call M2
294-
> D cd3 = cd1 + cd2;
294+
> D? cd3 = cd1 + cd2;
295295
> cd3(10); // call M1 then M2
296296
> cd3 += cd1;
297297
> cd3(20); // call M1, M2, then M1
298298
> C c = new C();
299299
> D cd4 = new D(c.M3);
300300
> cd3 += cd4;
301-
> cd3(30); // call M1, M2, M1, then M3
301+
> cd3!(30); // call M1, M2, M1, then M3
302302
> cd3 -= cd1; // remove last M1
303-
> cd3(40); // call M1, M2, then M3
303+
> cd3!(40); // call M1, M2, then M3
304304
> cd3 -= cd4;
305-
> cd3(50); // call M1 then M2
305+
> cd3!(50); // call M1 then M2
306306
> cd3 -= cd2;
307-
> cd3(60); // call M1
307+
> cd3!(60); // call M1
308308
> cd3 -= cd2; // impossible removal is benign
309-
> cd3(60); // call M1
309+
> cd3!(60); // call M1
310310
> cd3 -= cd1; // invocation list is empty so cd3 is null
311311
> // cd3(70); // System.NullReferenceException thrown
312312
> cd3 -= cd1; // impossible removal is benign

standard/expressions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3218,7 +3218,7 @@ Except for the `stackalloc` operator, C# provides no predefined constructs for m
32183218
>
32193219
> public class Widget<T>
32203220
> {
3221-
> public static implicit operator Widget<T>(Span<double> sp) { return null; }
3221+
> public static implicit operator Widget<T>(Span<double> sp) { return null!; }
32223222
> }
32233223
> ```
32243224
>
@@ -3800,7 +3800,7 @@ The predefined addition operators are listed below. For numeric and enumeration
38003800
> {
38013801
> static void Main()
38023802
> {
3803-
> string s = null;
3803+
> string? s = null;
38043804
> Console.WriteLine("s = >" + s + "<"); // Displays s = ><
38053805
>
38063806
> int i = 1;
@@ -6389,8 +6389,8 @@ The run-time processing of a simple assignment of the form `x = y` with type `T`
63896389
>
63906390
> <!-- Example: {template:"standalone-console", name:"SimpleAssignment1", expectedException:"ArrayTypeMismatchException"} -->
63916391
> ```csharp
6392-
> string[] sa = new string[10];
6393-
> object[] oa = sa;
6392+
> string?[] sa = new string[10];
6393+
> object?[] oa = sa;
63946394
> oa[0] = null; // OK
63956395
> oa[1] = "Hello"; // OK
63966396
> oa[2] = new ArrayList(); // ArrayTypeMismatchException

standard/statements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,7 @@ using (ResourceType rN = eN)
19261926
> }
19271927
> using (TextReader r = File.OpenText("log.txt"))
19281928
> {
1929-
> string s;
1929+
> string? s;
19301930
> while ((s = r.ReadLine()) != null)
19311931
> {
19321932
> Console.WriteLine(s);

tools/example-templates/additional-files/HelpAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public string Topic
1010
{
1111
get;
1212
set;
13-
}
13+
} = null!;
1414

15-
public string Url { get; }
15+
public string Url { get; } = null!;
1616
}

0 commit comments

Comments
 (0)