Skip to main content
gamedev.net
🔒 Locked

[.net] C# Array List

Started by OpenGL_Guru 6 replies 4.9k views
Original Post
OpenGL_Guru
OpenGL_Guru
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!
heh
Pseudonym
Pseudonym
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().
jpetrie
jpetrie
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.
OpenGL_Guru
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?)

heh
Washu
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.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
OpenGL_Guru
OpenGL_Guru
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..
heh
gharen2
gharen2
Visual studio 2005 uses .net 2.0
Visual studio 2003 uses .net 1.1

If you're not using 2005, upgrade asap.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.