Overload member methods - CSharp Custom Type

CSharp examples for Custom Type:overload

Description

Overload member methods

Demo Code

using static System.Console;
using System;//from  w  w  w .ja  v a  2 s  . c o  m
using System.Collections.Generic;
class Program
{
   static void Main(string[] args)
   {
      var p1 = new Person();
      WriteLine(p1.SayHello());
      WriteLine(p1.SayHello("Emily"));
   }
}
public class Person : object
{
   public string Name;
   public DateTime DateOfBirth;
   public List<Person> Children = new List<Person>();
   public readonly DateTime Instantiated;
   public const string Species = "Programmer";
   public readonly string HomePlanet = "Earth";
   public Person()
   {
      Name = "Unknown";
      Instantiated = DateTime.Now;
   }
   public string SayHello()
   {
      return $"{Name} says 'Hello!'";
   }
   public string SayHello(string name)
   {
      return $"{Name} says 'Hello {name}!'";
   }
}

Result


Related Tutorials