Different ways to make Method Parameter Optional in C#

PHOTO EMBED

Tue Sep 21 2021 03:51:03 GMT+0000 (UTC)

Saved by @dejohnny #c#

using System;
using System.Runtime.InteropServices;
  
class GFG {
  
    // Method containing optional parameter
    // Using OptionalAttribute
    static public void my_mul(int num,
                [ Optional ] int num2)
    {
        Console.WriteLine(num * num2);
    }
  
    // Main Method
    static public void Main()
    {
        my_mul(4);
        my_mul(2, 10);
    }
}
content_copyCOPY

C# program to illustrate how to create optional parameters using OptionalAttribute