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

  • SEARCH
  • Home
  • 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 4537398
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:40:13+00:00 2026-05-21T14:40:13+00:00

I have 2 functions, one that gets a name and the other that is

  • 0

I have 2 functions, one that gets a name and the other that is being set up to Delete from the list of name. There are no compliation errors, but my DeleteName doesn’t display anything. Probally a simple fix, what did I overlook?

    public static List<string> GetName(List<string> aString)
    {
        aString = new List<string>();
        localList.Add("cat");
        localList.Add("apple");
        localList.Add("bass");
        localList.Add("dog");
      return aString;
    }
    public static List<string> DeleteName(List<string> aString)
    {
        aString = new List<string>();
        GetName(aString);
        foreach (string x in aString)
        {
            Console.WriteLine(x);
        }
        return aString;
    }
  • 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-05-21T14:40:14+00:00Added an answer on May 21, 2026 at 2:40 pm

    It seems odd that you are passing the List and then returning it as well. Try changing your code to this:

    public static List<string> GetName()
    {
        List<string> aString = new List<string>();
        aString.Add("cat");
        aString.Add("apple");
        aString.Add("bass");
        aString.Add("dog");
      return aString;
    }
    public static List<string> DeleteName()
    {
        List<string>  aString = GetName();
        foreach (string x in aString)
        {
            Console.WriteLine(x);
        }
        return aString;
    }
    

    As @hunter points out you could do this without declaring your list in GetName. Code:

        public static void GetName(List<string> aString)
        {
            aString.Add("cat");
            aString.Add("apple");
            aString.Add("bass");
            aString.Add("dog");
        }
        public static List<string> DeleteName()
        {
            List<string> aString = new List<string>();
            GetName(aString);
            foreach (string x in aString)
            {
                Console.WriteLine(x);
            }
            return aString;
        }
    

    Also, as @Dustin Laine pointed out but then deleted, you will get the same result if you do not set aString to a new object in GetName(). Code:

    public static List<string> GetName(List<string> aString)
    {
        //aString = new List<string>();
        aString.Add("cat");
        aString.Add("apple");
        aString.Add("bass");
        aString.Add("dog");
        return aString;
    }
    public static List<string> DeleteName(List<string> aString)
    {
        aString = new List<string>();
        GetName(aString);
        foreach (string x in aString)
        {
            Console.WriteLine(x);
        }
        return aString;
    }
    

    This still seems like a very strange way to write your code and I would not recommend it.

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

Sidebar

Related Questions

I have 2 functions that needs to be executed one after the other. In
I have a set of five functions, that could be called one of five
I have 4 functions that do something I feel one can do. function getDownline(rankid,
I have an StackOverflowException in one of my DB functions that I don't know
I have this function that switches the HTML contents from one element on a
I have the following php array that gets all values from a form full
I have an html menu, when one item from it gets clicked I want
I have a class that specifies a set of callback functions (shown here as
I have one function ParseHtmlTable(string htmlContent) . Now in that function I want to
I have one javascript function that used to display the menu and content in

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.