I am trying to return a collection from a function. Here is my syntax....Anything obvious...?
Code:using System; using System.Collections.Specialized; namespace parsetxt { /// <summary> /// Summary description for Class1. /// </summary> class Class1 { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { parseClass pclass = new parseClass(); StringCollection p = pclass.parseIt("lease.txt"); foreach(char s in p.ToString()) { Console.WriteLine("---" + p.ToString()); } // // TODO: Add code to start application here // } } class parseClass { public StringCollection parseIt(string fl) { // Read the file as one string. System.IO.StreamReader myFile = new System.IO.StreamReader(fl); string myReadLine = myFile.ReadLine(); string[] mySplitLine; string myMAC; StringCollection colMAC = new StringCollection(); //string myString = myFile.ReadToEnd(); while(myReadLine != null) { mySplitLine = myReadLine.Split('\t'); myMAC = mySplitLine[4].ToString(); colMAC.Add(myMAC); Console.WriteLine(myMAC); myReadLine = myFile.ReadLine(); } myFile.Close(); foreach(string f in myMAC) { Console.WriteLine(myMAC); } return colMAC; // Display the file contents. //Console.WriteLine(myString); // Suspend the screen. //Console.ReadLine(); } } }




Reply With Quote