• Advertisement
Sign in to follow this  

[.net] C# Array List

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement