EDIT: For a console application, not sure if someone can add that to the end of the title?
I could only think of it as a function, as I'm not too heavily into C# just yet.
What I'm doing is creating a MUD-style game as a console application, so players will read text describing a room, and will use numbers or y/n to select an option, and a response will generate depending on their input. As such, my code will be growing quite long, as I was wondering if there was a way to make it so if one section is complete and I want to repeat their choices, rather than make an if statement for the condition and re-paste the lines, if I could assign a value to a variable at the end of a section, and use System.Console.Readline(variable) to repeat what is within. Like a loop for when an input equals a certain value, but no looping, just stored so it's on call if I want to bring it up again. So people can make a choice, and re-make the choice if they wish.
I don't think I worded that very well, so I'll post some code as to what I'm wanting (I won't do datatype conversions to keep it minimalistic here).
int userInput;
bool opt1 = false;
//(Section 1 - These three lines are what I want repeated if they input '2')
System.Console.WriteLine("What would you like to do?");
System.Console.WriteLine("\n\n 1) Buy\n2) Repeat questionl\n");
userInput = System.Console.ReadLine();
if (userInput = 1) {
System.Console.WriteLine("What do you want to buy?");
System.Console.WriteLine("More things here...");
System.Console.Readline();
opt1 = true;
}
if(userInput = 2) {
//(Some line of code that repeats first three lines if opt = true)
}
Something like that, but I'd like, if possible, to write something that can call a number. So I can have section 1 within curly brackets with content inside, and then if I want that repeated later I could say System.Console.WriteLine(somefunction(1)); and have it repeat what is within the brackets for 1.
I can clarify if my post isn't easy to understand. Any help you can provide is appreciated, :).