0

I am going through a Udemy tutorial on .NET WebAPI/Entity Framework and the instructor has used exclamation mark syntax I have never seen before. He doesn't explain it, and I am struggling to find an explanation online.

Can anyone fill me in on what these exclamation marks are accomplishing here? I've only used them as equality operators (e.g., "!=" for "not equal to"), but this seems to be something else entirely:

example 1 (before ".User" and after "NameIdentifier)":

private int GetCurrentUserId() => int.Parse(_httpContextAccessor.HttpContext!.User
            .FindFirstValue(ClaimTypes.NameIdentifier)!);

Example two (after "SubmittedBy"):

.Where(i => i.SubmittedBy!.Id == GetCurrentUserId())

I tried omitting the exclamation marks and my requests worked just the same (tested w/ Swagger). I googled my question a few different ways, but couldn't find a phrasing that returned useful results. I hunted down Microsoft's "C# operators and expressions" documentation, but didn't see an explanation of it there.

0 Answers0