I'm a beginner in C# and am creating a little MadLibs console game for practice. It's all working and now I'm trying to make it better, code cleaner, etc. Just switched from individual strings to an array for the user input and the story output, but I think there must be a more efficient way to do both.
Player class
namespace MadLib
{
static class Player
{
public static string Input (string part)
{
string name;
Console.WriteLine("Please enter a {0}: ", part);
name = Console.ReadLine();
return name;
}
}
}
Story code block
static class Story
{
static public void Spooky()
{
string[] part = new string[10];
//ask player for words
part[0] = Player.Input("noun");
part[1] = Player.Input("adjective");
part[2] = Player.Input("adjective");
part[3] = Player.Input("adjective");
part[4] = Player.Input("occupation");
part[5] = Player.Input("occupation");
part[6] = Player.Input("occupation");
part[7] = Player.Input("adjective");
part[8] = Player.Input("noun");
part[9] = Player.Input("noun");
//output finished story
Console.WriteLine("They all agreed that it was a huge {0}, {1}, {2}, and {3}."
+" I have cross-examined these men, one of them a hard-headed "
+ "{4}, one a {5}, and one a moorland {6}"
+ ", who all tell the same story of this "
+ "{7} {8}, exactly corresponding to the {9} of the legend."
, part[0], part[1], part[2], part[3], part[4], part[5]
, part[6], part[7], part[8], part[9]);
}