Call member method with optional parameters - CSharp Custom Type

CSharp examples for Custom Type:Method Parameter

Description

Call member method with optional parameters

Demo Code

using static System.Console;
using System;//from  w  ww  .j  ava 2s  . co m
using System.Collections.Generic;
class Program
{
   static void Main(string[] args)
   {
      var p1 = new Person();
      WriteLine(p1.OptionalParameters());
   }
}
public class Person : object
{
   public string Name;
   public DateTime DateOfBirth;
   public readonly DateTime Instantiated;
   public Person()
   {
      Name = "Unknown";
      Instantiated = DateTime.Now;
   }
   public string OptionalParameters(string command = "Run!", double number = 0.0, bool active = true)
   {
      return $"command is {command}, number is {number}, active is {active}";
   }
}

Result


Related Tutorials