Docs: Wrong example code in "Discards - C# Guide"

Created on 2 Jan 2019  ยท  7Comments  ยท  Source: dotnet/docs

@sopepos commented on Wed Jan 02 2019

There's no "switch" statement in example code of "Pattern matching with switch and is" section.

   private static void ProvidesFormatInfo(object obj)         
   {
      if (obj is IFormatProvider fmt)
         Console.WriteLine($"{fmt} object");
      else if (obj is null) {
         Console.Write("A null object reference: ");
         Console.WriteLine("Its use could result in a NullReferenceException");
      }
      else
         Console.WriteLine($"Some object type without format information");
   }

๋ฌธ์„œ ์„ธ๋ถ€ ์ •๋ณด

โš  ์ด ์„น์…˜์„ ํŽธ์ง‘ํ•˜์ง€ ๋งˆ์„ธ์š”. docs.microsoft.com โžŸ GitHub ๋ฌธ์ œ ์—ฐ๊ฒฐ์— ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

Area - C# Guide P1

Most helpful comment

I think this issue is fixed in https://github.com/dotnet/samples/pull/936

All 7 comments

Hi team,
I'm moving this here since the suggestion is about the code
best regards

We should add a second sample here.

There also doesn't seem to be any use of the Discard in that example either.

I think "no switch" is not a problem with this example. The problem is that it is not related to the topic of article - discards.

Just noticed this as well. The Pattern matching with switch and is sample doesn't use discards at all.

I think this issue is fixed in https://github.com/dotnet/samples/pull/936

Closing, dotnet/samples#936 fixed this as well

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ike86 picture ike86  ยท  3Comments

gmatv picture gmatv  ยท  3Comments

sebagomez picture sebagomez  ยท  3Comments

Eilon picture Eilon  ยท  3Comments

sdmaclea picture sdmaclea  ยท  3Comments