Reading from a .txt while inside a class

I'm getting an error

is a field but is used as a type.

I've looked around here and tried putting it outside of the class like

private string[] patron = new line.Split(':');

public void readTxt()//method for reading info from a txt
{
    idNum = Convert.ToInt32(patron[0]);
    fName = patron[1];
    lName = patron[2];
    address = patron[3];
    city = patron[4];
    state = patron[5];
    zip = patron[6];
    emailAddress = patron[7];
    phoneNum = patron[8];
}

But that doesn't work either. I've also had it inside the method and received the same error. Any ideas?

Jon Skeet
people
quotationmark

This is the problem:

new line.Split(':');

That makes it look like you're trying to create an instance of a type called line (although without specifying any arguments).

You just want:

private string[] patron = line.Split(':');

... although doing that in an instance variable initializer is unlikely to work unless line is a static variable. That sounds like something that should be done in a constructor, or a method.

Indeed, given the name of your method, it sounds like you should be reading the value in your method (from the file) and then splitting it:

public void ReadText()
{
    string line = ...; // However you read a line
    string[] patron = line.Split(':');
    idNum = patron[0];
    ...
}

Or you could put that in the constructor for your type, e.g.

public Person(string line)
{
    string[] patron = line.Split(':');
    idNum = patron[0];
    ...
}

people

See more on this question at Stackoverflow