Hi.
I have a question regarding the ArrayList.
In my code I use the arraylist to store objects of certain class.
I do not mix object types in the same ArrayList.
public ArrayList adresses = new ArrayList();
I store only objects from the class "CAdresses" in this ArrayList.
Now, every time I use the objects in the ArrayList I have to type cast them
into aCAdresses class type object since the compiler only knows it is a
object.
I want to declare the ArrayList so that it is known to the compiler which
type is stored in there so that I do not need the bulky syntax, and can use
intellisense.
Best regards, Jens 3 13941
Hello,
Try to use
public List<CAdresses> adresses = new List<CAdresses> ();
But this only works in C# 2.0. In 1.1. you have to cast ArrayList members to
class you need.
Best regards,
Andrew
"Jens Stjärna" wrote: Hi. I have a question regarding the ArrayList. In my code I use the arraylist to store objects of certain class. I do not mix object types in the same ArrayList.
public ArrayList adresses = new ArrayList();
I store only objects from the class "CAdresses" in this ArrayList. Now, every time I use the objects in the ArrayList I have to type cast them into aCAdresses class type object since the compiler only knows it is a object. I want to declare the ArrayList so that it is known to the compiler which type is stored in there so that I do not need the bulky syntax, and can use intellisense.
Best regards, Jens
The Generics feature in c# 2.0 supports exactly this.
- Atul
Sky Software http://www.ssware.com/
Shell MegaPack ActiveX & .Net
Drop-In Windows Explorer-Like Shell Browsing UI for your apps.
"Jens Stjärna" <je**********@N OSPAMcallenberg .se> wrote in message
news:DB******** *************** ***********@mic rosoft.com... Hi. I have a question regarding the ArrayList. In my code I use the arraylist to store objects of certain class. I do not mix object types in the same ArrayList.
public ArrayList adresses = new ArrayList();
I store only objects from the class "CAdresses" in this ArrayList. Now, every time I use the objects in the ArrayList I have to type cast them into aCAdresses class type object since the compiler only knows it is a object. I want to declare the ArrayList so that it is known to the compiler which type is stored in there so that I do not need the bulky syntax, and can use intellisense.
Best regards, Jens
Jens Stjärna wrote: I want to declare the ArrayList so that it is known to the compiler which type is stored in there so that I do not need the bulky syntax, and can use intellisense.
In addition to what other have suggested about Generics in .NET 2.0, the
normal way to do this in .NET 1 was to derive your own collection class
from CollectionBase. Try looking at the MSDN docs for this class, I
think there's a template implementation there that you can use quickly
to create your own typed collection classes.
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: vince |
last post by:
Can I add (append) to an xml file that already contains a
serialized object, and be able to deserialize to either
or both objects from the same file...??? How is this
done...??
thanks,
vince
|
by: Jax |
last post by:
I dont seem to fully comprehend references to objects yet.
Lets say for example I do this;
Customer c = new Customer();
Customer c1 = c;
I understand that if I change c1, I also change c as they
are both referencing the same piece of data.
But this isn't always the case it would seem.
Sometimes I take a reference out, change it and then go
|
by: hazz |
last post by:
If this makes sense, I would like to convert an arraylist of objects
returned from foo() into an array of the objects themselves per;
private Customer customers;
private int idx = 0;
public CustomerQueueService()
{
customers = new Customer ;
customers = foo(); //I want to copy the returned arraylist
|
by: Jens Stjärna |
last post by:
Hi.
I have a question regarding the ArrayList.
In my code I use the arraylist to store objects of certain class.
I do not mix object types in the same ArrayList.
public ArrayList adresses = new ArrayList();
I store only objects from the class "CAdresses" in this ArrayList.
Now, every time I use the objects in the ArrayList I have to type cast them
into aCAdresses class type object since the compiler only knows it is a
|
by: Arjen |
last post by:
Hi,
public class test {
public ArrayList myList = new ArrayList();
}
test myTest = new test();
myTest.myList.Add(<someobject>);
This results in an error.
| |
by: RCS |
last post by:
So I have an ArrayList that gets populated with objects like:
myAL.Add(new CustomObject(parm1,parm2));
I'm consuming this ArrayList from an ObjectDataSource and would like to have
this support sorting (because it's ultimately being consumed in a GridView).
I can't simply sort the ArrayList (because it only knows it's holding a
bunch of objects). So I need a way to sort the ArrayList, based on the
data - that is within the objects that...
|
by: Rob Meade |
last post by:
Dear all,
I have a class which contains an arraylist populated with other objects, for
example:
PrescriptionQueue - containing multiple instances of Prescription
I have the need on my web page to display this data which I have done,
however, now I would like to sort it based on a data item/direction selected
by the user from the web page.
|
by: budy_ludy |
last post by:
Hi All,
I am new to vb .net,
I have an ArrayList and i store class objects in it,
and later i want to retrieve each ArrayList items and type cast to the
class,
How can it be done ?
I used CType for casting but it is throwing exception.
|
by: netnet |
last post by:
I have a collection of objects that I store in the session. Then I look in
that collection to see if the collection.contains an object. it answers
false. If I dont store that collection in the session it answers true. Is
the session somehow modifying the collection? The objects look identical.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| | |