A
Adrian McNally
Hiya
I'm trying to get a list of news groups from a server into a array list by
using the following code, and then display the choosen group. When i compile
and run the code the only thing it displays is
"System.Collections.ArrayList". Can anyone gimme a hand, or tell me what i
have done wrong?
Thanks in advance.
using System;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Text;
class nntp
{
static void Main (string[] args)
{
TcpClient nntp = new TcpClient();
ArrayList nGroups = new ArrayList();
nntp.Connect("news.microsoft.com", 119);
NetworkStream nStream = nntp.GetStream();
StreamReader reader = new StreamReader(nStream);
StreamWriter writer = new StreamWriter(nStream);
string s;
reader.ReadLine();
writer.WriteLine("List");
writer.Flush();
s = reader.ReadLine();
s = s.Substring (0, 3);
while (s != ".")
{
s = reader.ReadLine();
if (s != ".")
{
s = s.Substring (0, s.IndexOf(' '));
nGroups.Add(s);
}
}
Random rand = new Random();
int num = rand.Next (0, nGroups.Count);
object rnntp = nGroups[num];
Console.WriteLine("The random group is " + nGroups);
Console.ReadLine();
}
}
I'm trying to get a list of news groups from a server into a array list by
using the following code, and then display the choosen group. When i compile
and run the code the only thing it displays is
"System.Collections.ArrayList". Can anyone gimme a hand, or tell me what i
have done wrong?
Thanks in advance.
using System;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Text;
class nntp
{
static void Main (string[] args)
{
TcpClient nntp = new TcpClient();
ArrayList nGroups = new ArrayList();
nntp.Connect("news.microsoft.com", 119);
NetworkStream nStream = nntp.GetStream();
StreamReader reader = new StreamReader(nStream);
StreamWriter writer = new StreamWriter(nStream);
string s;
reader.ReadLine();
writer.WriteLine("List");
writer.Flush();
s = reader.ReadLine();
s = s.Substring (0, 3);
while (s != ".")
{
s = reader.ReadLine();
if (s != ".")
{
s = s.Substring (0, s.IndexOf(' '));
nGroups.Add(s);
}
}
Random rand = new Random();
int num = rand.Next (0, nGroups.Count);
object rnntp = nGroups[num];
Console.WriteLine("The random group is " + nGroups);
Console.ReadLine();
}
}