My code looks something like this, but I have shortened it a little.
public static void mainvoid()
{
string line = Console.ReadLine().ToLower();
if (line == "restart")
{
Console.Clear();
Main();
}
if (line == "enter a value: ")
{
string value = console.ReadLine();
console.writeline("Your value is {0}", value);
mainvoid();
}
if (line == "my name")
{
Console.WriteLine("Your name is {0}", ConsoleApplication1.Properties.Settings.Default.name);
mainvoid();
}
I want my program to pick up a command (witch I have done) and some of them have values/strings after them E.g.
By the way I am using c# 2010
I want my command to look like this
My name is Daniel
and so the string/value = Daniel
or
name = billy
so the string/value = billy
So I want it to pick it up via console.readline(); and pick out that it is changing the name and after that will be the name in which it will be changed to.
But I don’t know how to make the last bit the value/string that I can also use.
Please leave a comment if you can help me 🙂
I can see that there are two issues here, one is extracting the persons name from the “my name is xyz” command, the other is saving that value for later in the program.
Because of the way you’ve structured your
mainmethod, and the fact that it calls itself (this is called recursion), it cannot share any variables from one call to the next. This makes it impossible to store the persons name. You could eliminate the recursion by instead creating a loop in themainmethodThis will continuously allow the user to enter commands, and the program will terminate when the user enters “exit”.
Now onto the problem of storing the users name, you can simply remove the “my name is” part of the sentence to get the users name…
I hope that gets you moving!