Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of (VB6) IsMissing in C#?

Here's what I get in VB6 Description:

enter image description here

How to do this in c#?

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

like image 348
jclima05 Avatar asked Mar 13 '23 16:03

jclima05


1 Answers

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
    } 
}
like image 111
Rob Avatar answered Mar 23 '23 14:03

Rob