Mark parameters as NOT nullable in C#/.NET?

后端 未结 6 2018
粉色の甜心
粉色の甜心 2020-12-02 21:53

Is there a simple attribute or data contract that I can assign to a function parameter that prevents null from being passed in C#/.NET? Ideally this would also

6条回答
  •  我在风中等你
    2020-12-02 22:24

    I know this is a VERY old question, but this one was missing here:

    If you use ReSharper/Rider you may use the Annotated Framework.

    Edit: I just got a random -1 for this answer. That's fine. Just be aware it is still valid, even though it's not the recommended approach for C#8.0+ projects anymore (to understand why, see Greg's answer).

提交回复
热议问题