saiful
saiful

Reputation: 159

need to use return type string array method

i have a method

public string[] getlist()
    {
      -----
      -----
      Return Result.toString();
    }

How do i call this method in my main method and show all the list using console.write(result) in loop

Thanks

Upvotes: 2

Views: 4462

Answers (3)

barbary
barbary

Reputation: 81

Obviously that method is incorrect as it's trying to return a string instead of an array.

However assuming myObject is an instance of what ever Object type has this method.

foreach(string str in myObject.getlist())
{
  Console.WriteLine(str);
}

Upvotes: 1

Shadow Wizard
Shadow Wizard

Reputation: 66388

Simple Join() will do the work just fine no need in loop:

Console.Write(string.Join(", ", myObj.getList()));

Upvotes: 2

Ivan Crojach Karačić
Ivan Crojach Karačić

Reputation: 1911

use a foreach (var result in retrivedString) {Console.Write(result);}

Upvotes: 1

Related Questions