Как я выполняю итерации набора.Net IList в обратном порядке?

Попробуйте следующее:

//Find the action bar for customizations
    final ActionBar ab = getSupportActionBar();
    assert ab != null;

    //Make the action bar display an up arrow and set its drawable and color
    ab.setDisplayHomeAsUpEnabled(true);
    final Drawable upArrow = ResourcesCompat.getDrawable(
            getResources(),
            R.drawable.abc_ic_ab_back_mtrl_am_alpha, //this is the <- arrow from android resources. Change this to the thing you want.
            null);
    assert upArrow != null;
    upArrow.setColorFilter(
            ContextCompat.getColor(
                    getApplicationContext(),
                    R.color.white // change this to the color you want (or remove the setColorFilter call)
            ),
            PorterDuff.Mode.SRC_ATOP);
    ab.setHomeAsUpIndicator(upArrow);
5
задан Gishu 18 September 2008 в 08:44
поделиться

3 ответа

Если у Вас есть.NET 3.5, Вы могли бы использовать Реверс LINQ?

foreach(var item in obEvtArgs.NewItems.Reverse())
{
   ...
}

(Принятие Вы говорите об универсальном IList),

7
ответ дан 14 December 2019 в 01:21
поделиться

NewItems является мой Список здесь... Это немного неуклюже все же.

for(int iLooper = obEvtArgs.NewItems.Count-1; iLooper >= 0; iLooper--)
            {
                GoViewBoy.Document.Add(CreateNodeFor(obEvtArgs.NewItems[iLooper] as IMySpecificObject, obNextPos));
            }
0
ответ дан 14 December 2019 в 01:21
поделиться

На основе комментариев к ответу Davy и исходному ответу Gishu, Вы могли бросить свое со слабым контролем типов System.Collections.IList к универсальному набору с помощью System.Linq.Enumerable.Cast дополнительный метод:

var reversedCollection = obEvtArgs.NewItems
  .Cast<IMySpecificObject>( )
  .Reverse( );

Это удаляет шум обоих реверс for цикл, и as бросок для получения объекта со строгим контролем типов от исходного набора.

2
ответ дан 14 December 2019 в 01:21
поделиться
Другие вопросы по тегам:

Похожие вопросы: