Created
February 19, 2017 23:13
-
-
Save janellbaxter/2d4489f11ed533c9ecffc475fd5f9ac7 to your computer and use it in GitHub Desktop.
6.4 Overloaded Method; Programming is Fun: C# Adventure Game (Learn C#)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 6.4 Overloaded Method | |
* Example code from Programming is Fun: C# Adventure Game | |
* Learn C# (for beginners) | |
* http://programmingisfun.com/learn/c-sharp-adventure-game | |
*/ | |
using System; | |
namespace Dialog | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Dialog("One argument version"); | |
Dialog("Two argument version with green", "green"); | |
Dialog("Two argument version with yellow", "yellow"); | |
Console.ReadKey(); | |
} | |
//original Dialog method | |
static void Dialog(string message) | |
{ | |
Console.ForegroundColor = ConsoleColor.Cyan; | |
Console.WriteLine(message); | |
Console.ResetColor(); | |
} | |
//new method | |
static void Dialog(string message, string color) | |
{ | |
if (color == "red") | |
{ Console.ForegroundColor = ConsoleColor.Red; } | |
else if (color == "green") | |
{ Console.ForegroundColor = ConsoleColor.Green; } | |
else if (color == "yellow") | |
{ Console.ForegroundColor = ConsoleColor.Yellow; } | |
else | |
{ Console.ForegroundColor = ConsoleColor.White; } | |
Console.WriteLine(message); | |
Console.ResetColor(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment