System.Array does not contain a definition for 'Split'

user1729696 picture user1729696 · Oct 8, 2012 · Viewed 14k times · Source

I'm trying to take a string and split it. However, whenever I use fullName.Split Visual Studio says System.Array does not contain a definition for Split.

This is my main method so far.

   public static void Main(string[] args)
    {
        string inValue;
        int noNames;
        string[] names = new string[100];
       // find number of names
        Console.WriteLine("Enter the number of names: ");
        inValue = Console.ReadLine();
        int.TryParse(inValue, out noNames);
        string[] fullName = new string[noNames];
        for (int i = 0; i < fullName.Length; i++)
        {
            string[] name = fullName.Split(' '); //error appears here
        }
    }

What's strange is that I was able to write another program shortly before this that uses the Split method. That program had no issues. I'm not sure if there is something wrong with my code, or an error with Visual Studio. Can anyone assist me in solving this error? The program isn't complete, if that matters.

Answer

PiousVenom picture PiousVenom · Oct 8, 2012

You need to call it on the element of the array, not the array itself.. So it would be:

string[] name = fullName[i].Split(' ');