[.net] C# Array List

This topic is 4048 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

hi all i have a C# Array List with some elements that i have added to it. what i am trying to do is use the C++ version of a vector. i think this is the right tool to use. however when i compare a double to an element of the List it complains:
Quote:
 error CS0019: Operator '>=' cannot be applied to operands of type 'double' and object'
maybe i am not using the right 'container' where i need to make sure the object has elements of type double or how would i go about this? thanks!

Share on other sites
Either define your list like so:

using System.Collections.Generic;...List<double> doubleList = new List<double>();

Or during your >= comparison convert the list operand to double using Convert.ToDouble().

Share on other sites
Use the generic list, as above.
Your error was likely due to the fact that the compile sees the contents of ArrayList as objects, not doubles (when you put doubles in the list, they are boxed to objects). You'd have to cast the object back to a double for the compiler to allow the comparison.

List<T> is better anyways.

Share on other sites
thanks all i went ahead and casted them as doubles as i was comparing them. out of curiousity i added the Generic namespace but i got the following error:

Quote:
 error CS0234: The type or namespace name 'Generic' does not exist in the class or namespace 'System.Collections' (are you missing an assembly reference?)

Share on other sites
Quote:
Original post by OpenGL_Guru
thanks all i went ahead and casted them as doubles as i was comparing them. out of curiousity i added the Generic namespace but i got the following error:

Quote:
 error CS0234: The type or namespace name 'Generic' does not exist in the class or namespace 'System.Collections' (are you missing an assembly reference?)

Sounds like you're using .Net 1.1. So, you'll have to do the casting method to unbox the double.

Share on other sites
Quote:
Original post by Washu
Quote:
Original post by OpenGL_Guru
thanks all i went ahead and casted them as doubles as i was comparing them. out of curiousity i added the Generic namespace but i got the following error:

Quote:
 error CS0234: The type or namespace name 'Generic' does not exist in the class or namespace 'System.Collections' (are you missing an assembly reference?)

Sounds like you're using .Net 1.1. So, you'll have to do the casting method to unbox the double.

i have the .NET Framework 2.0, at least its listed in my add/remove programs..

Share on other sites
What IDE are you using?

Share on other sites
Visual studio 2005 uses .net 2.0
Visual studio 2003 uses .net 1.1

If you're not using 2005, upgrade asap.

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
11
5. 5

• 14
• 30
• 13
• 11
• 11
• Forum Statistics

• Total Topics
631777
• Total Posts
3002305
×