Passing null arguments to C# methods

前端 未结 7 1924
野的像风
野的像风 2020-12-14 06:46

Is there a way to pass null arguments to C# methods (something like null arguments in c++)?

For example:

Is it possible to translate the following c++ functi

相关标签:
7条回答
  • 2020-12-14 07:20

    You can use NullableValueTypes (like int?) for this. The code would be like this:

    private void Example(int? arg1, int? arg2)
    {
        if(!arg1.HasValue)
        {
            //do something
        }
        if(!arg2.HasValue)
        {
            //do something else
        }
    }
    
    0 讨论(0)
提交回复
热议问题