473,499 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help in class type converstion

I am trying to use ArrayList to implement a class Wordlist.

Wordlist wordlist;

public ListOfData()
{
wordlist = new ArrayList();
}

But then when I try to access the objects in the ArrayList, Object is
returned instead of type Wordlist. What should I do in order to access the
member functions of wordlist?
Nov 15 '05 #1
3 1007
inherit Wordlist from ArrayList and then just call wordlist = new
Wordlist();

"Cheryl" <ch********@NOSPAM.cuhk.edu.hk> wrote in message
news:et**************@TK2MSFTNGP12.phx.gbl...
I am trying to use ArrayList to implement a class Wordlist.

Wordlist wordlist;

public ListOfData()
{
wordlist = new ArrayList();
}

But then when I try to access the objects in the ArrayList, Object is
returned instead of type Wordlist. What should I do in order to access the member functions of wordlist?

Nov 15 '05 #2
Cheryl <ch********@NOSPAM.cuhk.edu.hk> wrote:
I am trying to use ArrayList to implement a class Wordlist.

Wordlist wordlist;

public ListOfData()
{
wordlist = new ArrayList();
}
That's not going to work to start with, as you've declared wordlist to
be of type Wordlist, not ArrayList.
But then when I try to access the objects in the ArrayList, Object is
returned instead of type Wordlist. What should I do in order to access the
member functions of wordlist?


Just cast when you retrieve the object, e.g.

Foo x = (Foo) myArrayList[0];

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Vadym Stetsyak <pd****@ukr.net> wrote:
inherit Wordlist from ArrayList and then just call wordlist = new
Wordlist();


In my experience there's rarely a good reason to inherit from
ArrayList. For strong typing, you'd use CollectionBase instead. For
most other purposes, it would be better to use composition rather than
inheritance.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4

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

Similar topics

5
2955
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
2
1269
by: Daniel Wilson | last post by:
I have an enumerated type like this: public __value enum MyType{ ABC = 1, DEF = 2, GHI = 3, JKL = 4 }; Later I have a for loop like this: for (ft = MyType::ABC; ft <= MyType::JKL; ft++){
4
1559
by: MRD | last post by:
Hi All, I found a useful bit of code on msdn in VC but need it in VB. I've started the conversion but can't quite finish. The code puts a custom Icon on a toolbar (In my case the Word Add-in...
3
1636
by: =?Utf-8?B?Q2Fpcm4=?= | last post by:
I have some XML data which I wish to relate to existing classes, but data does not map exactly so serialsation will not work, the other consideration is that some of the XML data will need...
0
7007
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
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6894
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
5470
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,...
1
4919
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...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.