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;
}
It seems odd that you are passing the List and then returning it as well. Try changing your code to this:
As @hunter points out you could do this without declaring your list in
GetName. Code:Also, as @Dustin Laine pointed out but then deleted, you will get the same result if you do not set
aStringto a new object inGetName(). Code:This still seems like a very strange way to write your code and I would not recommend it.