Skip to content

C# Script to Delete All Measures #377

Discussion options

You must be logged in to vote

In C#, you can't modify a collection while iterating it, so you have to copy the items into a new collection like so:

var delete_measures = Model.Tables["Test Model"].Measures.ToList(); // .ToList() creates a copy of the collection

foreach(var measure in delete_measures) {
    measure.Delete(); 
    // No reason to look up the measure by name, since we already have a reference to it...
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Declan1984
Comment options

Answer selected by Declan1984
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants