c# - Reading from a .txt while inside a class -


i'm getting error

is field used type.

i've looked around here , tried putting outside of class like

private string[] patron = new line.split(':');  public void readtxt()//method reading info 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 doesn't work either. i've had inside method , received same error. ideas?

this problem:

new line.split(':'); 

that makes you're trying create instance of type called line (although without specifying arguments).

you want:

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

... although doing in instance variable initializer unlikely work unless line static variable. sounds should done in constructor, or method.

indeed, given name of method, sounds should reading value in method (from file) , splitting it:

public void readtext() {     string line = ...; // read line     string[] patron = line.split(':');     idnum = patron[0];     ... } 

or put in constructor type, e.g.

public person(string line) {     string[] patron = line.split(':');     idnum = patron[0];     ... } 

Comments