Peter Van Akelyen
Peter Van Akelyen

Reputation: 137

System.String[] returned instead of array

I'm trying to return an array of strings but return test; only gives "System.String[]" as output. If I iterate through test[] all values are filled in correctly. What am I doing wrong?

 public static String[] ReturnTheStrings()
 {
     FillTheArray();
     String[] test = new String[178];

     for (int i = 0; i < 178; i++)
     {
         if ((Class7.Method4(strings[i])) == "decoding wrong")
         {
             test[i] = strings[i+1];
             //System.Console.WriteLine("Non-encoded value");
         }
         else
         {
             test[i] = Class7.Method4(strings[i+1]);
             //System.Console.WriteLine("Encoded value");
         }
     }
     return test;
 }

I'm using MS Visual C# 2010.

Upvotes: 8

Views: 43347

Answers (1)

jrummell
jrummell

Reputation: 43077

Calling .ToString() on an array will return "System.String[]". If you want to display each value in the array, you have iterate over it.

For example:

foreach (var value in test)
{
    Console.WriteLine(value);
}

Or, as @Oded pointed out in the comments, you can use String.Join:

Console.WriteLine(String.Join(Environment.NewLine, stringArray));

Upvotes: 22

Related Questions