What is the return _ in C#

If you are not using the parameter in a lambda, people use _ as a convention for indicating that.

In your code, it is the catchall case for if serviceType isn't resolved to a call site. Since you don't care about the serviceType to return null, _ is used for that parameter.

This is probably a duplicate of this post which has lots of info:

C# style: Lambdas, _ => or x =>?


_ is a valid C# identifier, so _ => null is the same as myServiceProvider => null

Defining what is a valid identifier is not as simple as checking the characters for a white list of allowed characters, but it's documented here

Tags:

C#

Asp.Net