Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8745179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:57:52+00:00 2026-06-13T11:57:52+00:00

My code looks something like this, but I have shortened it a little. public

  • 0

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 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:57:53+00:00Added an answer on June 13, 2026 at 11:57 am

    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 the mainmethod

    static public void Main()
    {
        string currentLine;
    
        do
        {
            currentLine = Console.ReadLine();
        }
        while (!currentLine.Equals("exit"))
    }
    

    This 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…

    static public void Main()
    {
        string username = "Matthew";
    
        string currentLine;
    
        do
        {
            currentLine = Console.ReadLine();
    
            if (currentLine.Equals("restart"))
            {
                Console.Clear();
            }
    
            if (currentLine.StartsWith("my name is"))
            {
                username = currentLine.Replace("my name is ", "");
            }
    
            if (currentLine.Equals("my name"))
            {
                Console.WriteLine("Your name is {0}", username);
            }
        }
        while (!currentLine.Equals("exit"))
    }
    

    I hope that gets you moving!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have jQuery code which looks something like this on Button1 Click $('table.result_grid tbody
I have code that looks something like this in javascript: forloop { //async call,
In my code, I have something that looks like this: @implementation MyClass - (id)
I have code that looks something like, #include<stdlib.h> #include<string.h> char** someArray = NULL; size_t
So I have a code that looks something like this $(.something).live({ mouseover:function(e){ //do stuff
The code I'm working with looks something like this: <% MessageInfo msg= hp.getInfo(transactionName, checkpointLoc);%>
My code looks something like: template <typename type> void deserialize_element(type* result) { //... if
I have a code that looks something like: struct Data { int value; };
I have some code in a couple of different functions that looks something like
All, I have an XML document that looks something like this: <root> <profile> <childA>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.