473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sockets and Arraylists

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

}

}
Nov 17 '05 #1
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();

}

}

Nov 17 '05 #2
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();

}

}

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
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
0
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;
5
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 ...
0
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...
3
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...
4
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...
2
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();...
1
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...
3
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...
0
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
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.