
Как удалить все элементы, кроме первого (индекс 0) и последнего (индекс изменится, но в данном случае это 299)?
Я пробовал это до сих пор:
Код: Выделить всё
try
{
// Get the number of items in the Beam sequence
var bmSQ1 = dicomDataset.GetSequence(DicomTag.BeamSequence).Items.Count();
for (int i = 0; i < bmSQ1; i++)
{
// Get number of items in the ControlPoint Sequence
var cpSQ = dicomDataset.GetSequence(DicomTag.BeamSequence).Items[i].GetSequence(DicomTag.ControlPointSequence).Items.Count();
var delItems = dicomDataset.GetSequence(DicomTag.BeamSequence).Items[i].GetSequence(DicomTag.ControlPointSequence).Items;
for (int y = 0; y < cpSQ-1 ; y++)
{
// Go inside each item in the ControlPoint sequence and get the ControlPoint Index #
var cpIndex = dicomDataset.GetSequence(DicomTag.BeamSequence).Items[i].GetSequence(DicomTag.ControlPointSequence).Items[y].GetSingleValueOrDefault(DicomTag.ControlPointIndex, "");
int newCP = cpSQ ;
string totalCPs = newCP.ToString();
// If is not the first (#0 ) or the last (totalCPs) execute the block
if (cpIndex != "0" && cpIndex != totalCPs)
{
// Console.WriteLine($"Remaining ControlPoint Index#:{cpIndex}");--correct output
delItems.RemoveAt(i); --index out of range error
// delItems.RemoveAt(y); -- index out of range error
}
}
}
Любое предложение будет принято с благодарностью
Подробнее здесь: https://stackoverflow.com/questions/790 ... dex-299-us