2

I'm reading about SignalR and I have found code:

  public ChannelReader<int> Counter(int count, int delay)
{
    var channel = Channel.CreateUnbounded<int>();

    // We don't want to await WriteItems, otherwise we'd end up waiting 
    // for all the items to be written before returning the channel back to
    // the client.
    _ = WriteItems(channel.Writer, count, delay);

    return channel.Reader;
}

What is the meaning of underscore? Is it variable?

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
Zet
  • 571
  • 3
  • 13
  • 31
  • 6
    https://learn.microsoft.com/en-us/dotnet/csharp/discards – juharr Oct 24 '18 at 15:47
  • Where did you find this code? Is it in SignalR's source code? Although it appears to be a discard, it also appears to be completely unnecessary. You could just not assign the result value to any variable/discard. – mason Oct 24 '18 at 15:59
  • @mason https://learn.microsoft.com/en-us/aspnet/core/signalr/streaming?view=aspnetcore-2.1 – Zet Oct 24 '18 at 16:06
  • 1
    @Zet The quality of the more expository MSDN pages is....not ideal. They often write code that ignores recommendations they've given in other places. – mason Oct 24 '18 at 16:20

1 Answers1

3

I could be wrong but it looks like a discard to me.

David Osborne
  • 6,436
  • 1
  • 21
  • 35