|
-
Feb 17th, 2004, 11:39 AM
#1
Thread Starter
Fanatic Member
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();
}
}
}
-
Feb 17th, 2004, 01:42 PM
#2
Frenzied Member
Looks ok to me. Are you getting any errors?
-
Feb 17th, 2004, 05:50 PM
#3
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|