Use Optional Parameters - CSharp Custom Type

CSharp examples for Custom Type:Method Parameter

Description

Use Optional Parameters

Demo Code


using System;//www  . j  ava 2s .c o  m
using System.Collections.Generic;
using System.Linq;
using System.Text;

class MainClass
    {
        static void Main(string[] args)
        {
            printMessage();
            printMessage("A");
            printMessage("B", "G");
            printMessage("J", "H", true);
        }

        static void printMessage(string from = "1", string message = "2", bool urgent = false)
        {
            Console.WriteLine("From: {0}, Urgent: {1}, Message: {2}", from, message, urgent);
        }
    }

Related Tutorials