Passing null arguments to C# methods

前端 未结 7 1993
野的像风
野的像风 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
        }
    }
    

提交回复
热议问题