Eduardo Fernando Teixeira:
When an item is deleted, the Total method returns the correct count of elements, but the index i refers to the next element which has become current element, so it remains untouched. when you want to delete an item inside a loop, an approach is a recursive function for deletion.
Hello, I'm really struggling with the way MQL5 implements lists, I wish it was simple as C#'s List class!
!
Mohammad Hossein Sadeghi:
When an item is deleted, the Total method returns the correct count of elements, but the index i refers to the next element which has become current element, so it remains untouched. when you want to delete an item inside a loop, an approach is a recursive function for deletion.
When an item is deleted, the Total method returns the correct count of elements, but the index i refers to the next element which has become current element, so it remains untouched. when you want to delete an item inside a loop, an approach is a recursive function for deletion.
Thank you Mohammad.
What about the methods to copy the current item in the iteration to a new instance, do you have any thoughts?
Eduardo Fernando Teixeira:
Thank you Mohammad.
What about the methods to copy the current item in the iteration to a new instance, do you have any thoughts?
No, take it easy, you can iterate from last to first, this is another approach for item deletion if the order of items is not important.
Mohammad Hossein Sadeghi:
No, take it easy, you can iterate from last to first, this is another approach for item deletion if the order of items is not important.
Thank you, will try that!
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello, I'm really struggling with the way MQL5 implements lists, I wish it was simple as C#'s List class!
I have this custom class:
What is the correct way to work with a collection of this object, using CList or CArrayObj? I just need to:
- Create objects and add to the collection
- Iterate the collection and work with each item
- Delete specific items from the collection during this iteration, if they match my criteria
I tried many variations but I always end up with some kind of problem.
What's the simplest and most effective way to work this? It can be either CList, CArrayObj or something else, I dont really care as long as it works!
Many thanks in advance!