简体   繁体   中英

Equivalent of (VB6) IsMissing in C#?

Here's what I get in VB6 Description:

在此输入图像描述

How to do this in c#?

PS I also don't know how to use optional parameter in c#.

As far as I'm aware, there's no exact equivalent.

public void DoSomething(SomeClass A = null) 
{

}

There is no difference in C# between the following:

DoSomething(null);
DoSomething();

The closest you'll get is a null check on A . For value types, you can check the default (Though VB6 IsMissing does not support 'simple data types').

That is, the translated version of:

Sub DoSomething(Optional A As SomeClass)
    If IsMissing(A) Then
        'Missing
    Else
        'Not missing
End Sub

Is:

public void DoSomething(SomeClass A = null) 
{
    if (A == null)
    {
        //Missing
    } else {
        //Not missing
    } 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM