Home > OS >  What is the difference between TaskMethodAsync(); and _ = TaskMethodAsync();?
What is the difference between TaskMethodAsync(); and _ = TaskMethodAsync();?

Time:09-24

In fact....i just want to hide compiler's warning!

code :

TaskMethodAsync()

_=TaskMethodAsync()

CodePudding user response:

There is no difference!

You get the warning for the first option, because when you have a function that returns a value, and you don't assign or otherwise use that value at all, that's a strong indication you don't understand the function and maybe have a bug.

The second option does not produce a warning because you were explicit about saying, "Yes, I am aware this method returns a value, but I really do mean to just throw it away."

  •  Tags:  
  • c#
  • Related