Results 1 to 3 of 3

Thread: Return a collection

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954

    Return a collection

    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();
    
    		}
    	}
    }

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Looks ok to me. Are you getting any errors?

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Shouldn't it be:????

    Code:
    foreach(string s in p)
    {
    Console.WriteLine("---" + s.ToString());
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width