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();
}
} 2 1593
Hi Adrian,
in the following line of your code: Console.WriteLine("The random group is " + nGroups);
you passed to ArrayList object to append to the string, this will call the
ToString() method on the ArrayList which by default will print the type of
the object which is why you see System.Collection.ArrayList.
You really want to say something like: Console.WriteLine("The random group is " + nGroups[i]);
where i is some valid index into the array.
Hope that helps
Mark R Dawson http://www.markdawson.org
"Adrian McNally" wrote:
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();
}
}
Thank you very much, with your help i've managed to get it work.
"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:A6**********************************@microsof t.com... Hi Adrian, in the following line of your code:
Console.WriteLine("The random group is " + nGroups);
you passed to ArrayList object to append to the string, this will call the ToString() method on the ArrayList which by default will print the type of the object which is why you see System.Collection.ArrayList.
You really want to say something like: Console.WriteLine("The random group is " + nGroups[i]);
where i is some valid index into the array.
Hope that helps Mark R Dawson http://www.markdawson.org
"Adrian McNally" wrote:
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();
}
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: godsella |
last post by:
First i have two stored procedures, i have passed the values of each
one into two different arraylists of dates. how can i compare the two
arraylists of dates?
Thanks in advance
|
by: Adrian McNally |
last post by:
Hiya, I'm trying to get all the news groups from a server into a arraylist
by using the following code.
using System;
using System.Collections;
using System.Net;
|
by: drdave |
last post by:
I would like to have ten arraylists created within a loop.. is there a
conversion or something I can do to acheive this..
pseudo:
Dim counter As Integer = 0
Dim ArrName As ArrayList
...
|
by: steve |
last post by:
I'm looking for a code example how to compare the values in a given record in different arraylists
two arraylists, two fields in each record, both defined as string
I'm thinking that it's...
|
by: steve |
last post by:
I need to compare the value of a field in a row on an arraylist with the value of a field on a second arraylist
I have this bit of code working for arrays but cant get it working for arraylists
The...
|
by: Andy in S. Jersey |
last post by:
I would like to create an unknown number of Arraylists, meaning, I don't know
how many I should create until runtime.
I will be reading a table, and 0,1,2, or more fields have to be put into...
|
by: Andy in S. Jersey |
last post by:
I would like to create an unknown number of ArrayLists, that is I don't know
that until runtime.
Of course I can do this if I knew I needed two:
ArrayList IntervalArray1 = new ArrayList();...
|
by: Newbie19 |
last post by:
I'm just learning java arrays/arraylists and was wondering what are the best books for learning java arrays/arraylists?
I know practice is the best way to learn, but I have a hard time...
|
by: =?Utf-8?B?Sm9zaFA=?= |
last post by:
Hi All, I am attempting to compare values in two arraylists to make sure all
the values are the same. I am running into trouble with my code if both
arraylists compare okay up until a point and I...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |