Usage of List<T>
Author: Sammy_G
Creation Date: 8/20/2010 1:37 PM
profile picture

Sammy_G

#1
This is almost too basic to ask...

Using the Weak-stock symbol rotation script as an example, one adds paired info (symbol, Value) into a list as follows:
CODE:
Please log in to see this code.

etc.

1) If one needs to retrieve and/or copy those values later one, how does one do that?
My attempt to retrieve them, and also transfer them to another list, have failed:
CODE:
Please log in to see this code.


2) Related question: To copy some of the (paired) items from one list to another list, it seems you can't use the Copy method as that apparently transfers from a List to an array (so my readings tell me). So one has to copy the values one holder by one holder, as in the (failed) example above?
profile picture

Eugene

#2
In this particular case, you could've used .CopyTo and .AddRange (untested):
CODE:
Please log in to see this code.
profile picture

Sammy_G

#3
Thanks, Eugene. I will check it out.

Meanwhile, I do want to know how to retrieve individual values (sym and/or value) from a list at some index value[w], say to print out or whatever. Can you help with that?
profile picture

Eugene

#4
I suggest checking out the MSDN/dotnetperls/Google et al. first with general C# questions.
profile picture

Sammy_G

#5
I already spent > 1 day doing that. They all give examples of simple, one-item lists which doesn't help in this case. Its only when I was unable to find the answer that I posed the question.
There is no published rotation script that can help out either.
profile picture

Eugene

#6
CODE:
Please log in to see this code.
profile picture

Sammy_G

#7
Hi Eugene,

With your mod, I am getting the following
Runtime error: At least one object must implement IComparable...
profile picture

Eugene

#8
Check your syntax carefully.

By the way, code in 1) could be simplified:
CODE:
Please log in to see this code.
profile picture

Sammy_G

#9
Thanks for the tip.

BTW, I realized the cause of the error was this lower down in the script:
BuyList.Sort();

When I changed it to
BuyList.Sort(this);

the error goes away. Can you enlighten me as to why this is so? (last question)
profile picture

Sammy_G

#10
Never mind, I figured out what 'this' is for.

Thank you very much for all the help!
profile picture

Eugene

#11
I guess because your iHolder doesn't implement the IComparable interface. That's why the need to provide a Comparison type.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).