本文整理汇总了C#中ICollection.OrderByDescending方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.OrderByDescending方法的具体用法?C# ICollection.OrderByDescending怎么用?C# ICollection.OrderByDescending使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.OrderByDescending方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindSolution
/// <summary>
/// Finds a solution for the passed packing problem instance data.
/// </summary>
/// <param name="stripWidth">
/// Width of the strip the items have to be packed into.
/// </param>
/// <param name="items">
/// Items that have to be packed.
/// </param>
/// <param name="maximumStripHeight">
/// Maximum strip height before the algorithm stops packing and returns.
/// </param>
/// <returns>
/// Maximum strip height that has been used.
/// </returns>
public float FindSolution(float stripWidth, ICollection<PackingItem> items, float maximumStripHeight)
{
// Add first level.
var highestLevel = this.AddLevel(0f);
// Sort items by decreasing height.
var itemList = items.OrderByDescending(item => item.Rectangle.Height).ToList();
foreach (var item in itemList)
{
// Find first level the current item fits.
var fittingLevel = this.Levels.FirstOrDefault(level => level.Width + item.Rectangle.Width <= stripWidth);
if (fittingLevel == null)
{
// Add new level on top.
highestLevel = this.AddLevel(highestLevel.Y + highestLevel[0].Rectangle.Height);
fittingLevel = highestLevel;
}
// Check if maximum strip height is exceeded.
if (maximumStripHeight > 0 && fittingLevel.Y + item.Rectangle.Height > maximumStripHeight)
{
break;
}
// Put item into fitting level.
item.Rectangle.X = fittingLevel.Width;
item.Rectangle.Y = fittingLevel.Y;
fittingLevel.AddItem(item);
}
return this.ComputeValue();
}
示例2: Handle
public override void Handle(OrderRules rule, ref ICollection<TeamInTableViewModel> teamsStats)
{
if (rule == OrderRules.SmallPointsRatio)
{
var teamInTableViewModels = teamsStats.OrderByDescending(t => t.PointsRatio);
teamsStats = teamInTableViewModels.ToList();
}
else if (Successor != null)
{
Successor.Handle(rule, ref teamsStats);
}
}
示例3: SortByLambdaExpression
public static void SortByLambdaExpression(ref ICollection<Student> students)
{
ICollection<Student> sortedCollection = new List<Student>();
var sortedObject = students.OrderByDescending(x => x.FirstName).ThenByDescending(x => x.LastName);
foreach (var item in sortedObject)
{
sortedCollection.Add(item);
}
students = sortedCollection;
}
示例4: LearnInternal
/// <summary>
/// Recursively construct decision tree from examples and attributes
/// </summary>
private static TreeNode LearnInternal(ICollection<Example> examples, ICollection<DataAttribute> attributes, IEnumerable<Example> parentExamples)
{
// if no examples, use parent plurality
if (examples.Count == 0)
{
return PluralityValue(parentExamples);
}
// if all examples have same classification, use it
if (examples.Select(x => x.ClassLabel).Distinct().Count() == 1)
{
return new TreeNode
{
ClassLabel = examples.First().ClassLabel,
};
}
// if no attributes, use plurality
if (attributes.Count == 0)
{
return PluralityValue(examples);
}
// pick most important attribute
var attr = attributes.OrderByDescending(x => Importance(examples, x)).First();
// get other attributes
var remainingAttrs = attributes.Where(x => x != attr).ToList();
// group the examples by their value for selected attribute
var examplesByAttrValue = examples.ToLookup(x => x.Attributes[attr.ColNum]);
// construct a decision tree for this attribute
var tree = new TreeNode
{
ColNum = attr.ColNum,
};
// for each value, recursively construct a sub-tree
foreach (var attrValue in attr.Values)
{
var childExamples = examplesByAttrValue[attrValue].ToList();
var subTree = LearnInternal(childExamples, remainingAttrs, examples);
tree.Children.Add(attrValue, subTree);
}
return tree;
}
示例5: GetCurrentVersion
/// <summary>
/// Returns the current version based on specified versioning style.
/// </summary>
/// <param name="versions">
/// The versions.
/// </param>
/// <param name="versioningStyle">
/// The versioning style.
/// </param>
/// <returns>
/// The current version.
/// </returns>
/// <exception cref="ArgumentNullException">
/// The <paramref name="versions"/> parameter is null.
/// </exception>
public static string GetCurrentVersion(ICollection<ProcessVersionInfo> versions, VersioningStyles versioningStyle)
{
if (versions == null || versions.Count == 0)
{
return null;
}
if (versioningStyle == VersioningStyles.Alphanumeric)
{
var versionInfo = versions.OrderByDescending(v => v.Id).First();
return versionInfo.VersionNumber;
}
return versions.Where(v => v.VersionNumber.Trim().Length == versions.Max(v1 => v1.VersionNumber.Trim().Length)).Max(v => v.VersionNumber.Trim());
}
示例6: SortStringWithQualityHeaderValuesByQFactor
/// <summary>
/// Sort Accept-Charset, Accept-Encoding, Accept-Language and related header field values with similar syntax rules
/// (if more than 1) in descending order based on q-factor.
/// </summary>
/// <param name="headerValues">The header values to sort.</param>
/// <returns>The sorted header values.</returns>
protected virtual IEnumerable<StringWithQualityHeaderValue> SortStringWithQualityHeaderValuesByQFactor(ICollection<StringWithQualityHeaderValue> headerValues)
{
if (headerValues == null)
{
throw Error.ArgumentNull("headerValues");
}
if (headerValues.Count > 1)
{
// Use OrderBy() instead of Array.Sort() as it performs fewer comparisons. In this case the comparisons
// are quite expensive so OrderBy() performs better.
return headerValues.OrderByDescending(m => m, StringWithQualityHeaderValueComparer.QualityComparer).ToArray();
}
else
{
return headerValues;
}
}
示例7: SortMediaTypeWithQualityHeaderValuesByQFactor
/// <summary>
/// Sort Accept header values and related header field values with similar syntax rules
/// (if more than 1) in descending order based on q-factor.
/// </summary>
/// <param name="headerValues">The header values to sort.</param>
/// <returns>The sorted header values.</returns>
protected virtual IEnumerable<MediaTypeWithQualityHeaderValue> SortMediaTypeWithQualityHeaderValuesByQFactor(
ICollection<MediaTypeWithQualityHeaderValue> headerValues)
{
if (headerValues.Count > 1)
{
// Use OrderBy() instead of Array.Sort() as it performs fewer comparisons. In this case the comparisons
// are quite expensive so OrderBy() performs better.
return headerValues
.OrderByDescending(m => m, MediaTypeWithQualityHeaderValueComparer.QualityComparer)
.ToArray();
}
else
{
return headerValues;
}
}
示例8: PlayTrumpCardAgainstCardFromSuit
/// <summary>
/// Find best trump card when do not have cards from the opponent card suit.
/// </summary>
/// <param name="context">The information about current turn.</param>
/// <param name="possibleCardsToPlay">Cards that player can play.</param>
/// <param name="opponentCard">Card that opponent have played.</param>
/// <returns>Find the optimal trump card to be played.</returns>
private Card PlayTrumpCardAgainstCardFromSuit(PlayerTurnContext context, ICollection<Card> possibleCardsToPlay, Card opponentCard)
{
var trumpCards = possibleCardsToPlay
.OrderByDescending(c => c.GetValue())
.ToList();
int botskoPoints = BotskoPlayer.BotskoIsFirstPlayer ?
context.FirstPlayerRoundPoints : context.SecondPlayerRoundPoints;
var biggestTrumpInHand = trumpCards.FirstOrDefault();
var smallestTrumpInHand = trumpCards.Last();
// Check if can win with opponent card points and biggest trump card points,
if (botskoPoints + biggestTrumpInHand.GetValue() + opponentCard.GetValue() >= 66)
{
return trumpCards.FirstOrDefault();
}
if (trumpCards.Count > 1)
{
if (this.playerAnnounce != null &&
this.playerAnnounce.Suit == biggestTrumpInHand.Suit)
{
// If have bigger trump card than King and smaller than Queen
// play smaller trump card.
if (biggestTrumpInHand.Type != CardType.King &&
smallestTrumpInHand.Type != CardType.Queen)
{
return smallestTrumpInHand;
}
// If have bigger trump card than King but the smallest is Queen
// play bigger trump card.
if (biggestTrumpInHand.Type != CardType.King &&
smallestTrumpInHand.Type == CardType.Queen)
{
return biggestTrumpInHand;
}
// If have bigger trump card than Kign but have 40 too
// play bigger trump card.
if (biggestTrumpInHand.Type == CardType.King)
{
return smallestTrumpInHand;
}
}
// Check if have more than 1 trump cards and the biggest in the game is in my hand.
// Then play the smallest trump card.
if (this.FirstTurnLogic.IsBiggestCardInMyHand(biggestTrumpInHand))
{
return smallestTrumpInHand;
}
}
return trumpCards.Last();
}
示例9: CreateAssigneeCollection
public static ICollection<AssigneeViewModel> CreateAssigneeCollection(ICollection<ProjectMembership> memberships)
{
if (memberships == null)
return new Collection<AssigneeViewModel>();
ICollection<AssigneeViewModel> members = new ObservableCollection<AssigneeViewModel>();
foreach (ProjectMembership m in memberships.OrderByDescending(m => m.IsActive).ThenBy(m => m.Role.PermissionSet))
if (!members.Any(mm => mm.MemberUId == m.MemberUId))
members.Add(new AssigneeViewModel(m));
return members;
}
示例10: GetSureCardsWhenGameClosed
public ICollection<Card> GetSureCardsWhenGameClosed(PlayerTurnContext context, ICollection<Card> cards, bool deckHasCards = true)
{
var sureCards = new List<Card>();
cards = cards.OrderByDescending(c => c.GetValue()).ToList();
var opponentsCards = this.RemainingCards.OrderByDescending(c => c.GetValue()).ToList();
foreach (var myCard in cards)
{
// if card is part of an announce => skip it
if (this.cardValidator.IsCardInAnnounce(context, myCard, cards, Announce.Forty)
|| this.cardValidator.IsCardInAnnounce(context, myCard, cards, Announce.Twenty))
{
continue;
}
// if opponent has no trump cards & no cards of myCard's suit & myCard is not trump => sure card
var opponentsCardsInSuit = opponentsCards.Where(c => c.Suit == myCard.Suit)
.OrderByDescending(c => c.GetValue()).ToList();
if (!this.cardValidator.HasTrumpCard(context, this.RemainingCards)
&& opponentsCardsInSuit.Count == 0) //&& myCard.Suit != this.TrumpSuit - TODO: check
{
sureCards.Add(myCard);
}
// add trump ace
if (deckHasCards && myCard.Type == CardType.Ace && myCard.Suit == this.TrumpSuit)
{
sureCards.Add(myCard);
}
// add trump ten if ace is played or in player
if (deckHasCards && myCard.Type == CardType.Ten && myCard.Suit == this.TrumpSuit
&& (this.FindPlayedCard(CardType.Ace, this.TrumpSuit) != null || this.FindMyRemainingTrumpCard(CardType.Ace) != null))
{
sureCards.Add(myCard);
}
foreach (var opponetCard in opponentsCardsInSuit)
{
// if opponent has any higher card in that suit
if (opponentsCardsInSuit.Any(c => c.GetValue() > myCard.GetValue()))
{
break;
}
if (myCard.GetValue() > opponetCard.GetValue())
{
if (deckHasCards)
{
// if game is closed but deck is not empty => add card if opponent has no trump cards || if it's top trumps
if (!this.cardValidator.HasTrumpCard(context, this.RemainingCards))
{
this.MySureTrickPoints += (myCard.GetValue() + opponetCard.GetValue());
sureCards.Add(myCard);
}
}
else
{
// if deck is empty => sure card
this.MySureTrickPoints += (myCard.GetValue() + opponetCard.GetValue());
sureCards.Add(myCard);
opponentsCards.Remove(opponetCard);
}
break;
}
}
}
return sureCards;
}
示例11: GetLastByTimestamp
private static MappedResultInfo GetLastByTimestamp(ICollection<MappedResultInfo> reduceKeyAndEtags)
{
if (reduceKeyAndEtags == null || reduceKeyAndEtags.Count == 0)
return null;
return reduceKeyAndEtags.OrderByDescending(x => x.Timestamp).First();
}
示例12: SortPlayersDescendingByScore
private ICollection<IPlayer> SortPlayersDescendingByScore(ICollection<IPlayer> allPlayers)
{
var sortedPlayers = allPlayers.OrderByDescending(p => p.Score).ToList();
return sortedPlayers;
}
示例13: CreateInternal
private void CreateInternal(IPlayerView world, ICollection<IVessel> enemies)
{
Coordinate coordinate;
int tries = 0;
Orientation orientation = Orientation.Horizontal;
foreach (IVessel enemy in enemies.OrderByDescending(v => v.Length))
{
Enemies.Add(enemy);
coordinate = RandomCoordinate;
orientation = Dice.Next(2) == 1 ? Orientation.Horizontal : Orientation.Vertical;
if (orientation == Orientation.Horizontal && coordinate.Latitude + enemy.Length > Boundaries.East)
coordinate.Latitude -= coordinate.Latitude + enemy.Length - Boundaries.East;
if (orientation == Orientation.Vertical && coordinate.Longitude - enemy.Length < 1)
coordinate.Longitude = enemy.Length;
if (AvoidEdge)
AvoidEdges(coordinate);
while (!world.PutShip(enemy.SailTo(coordinate.ToInterfaceCoordinate(), orientation)))
{
if (++coordinate.Latitude > Boundaries.East)
coordinate.Latitude = Boundaries.West;
if (++coordinate.Longitude > Boundaries.North)
coordinate.Longitude = Boundaries.South;
if (++tries > 10)
orientation = orientation == Orientation.Horizontal ? Orientation.Vertical : Orientation.Horizontal;
if (tries > 20)
{
tries = 0;
coordinate = RandomCoordinate;
}
if (AvoidEdge)
AvoidEdges(coordinate);
}
}
}
示例14: GetBestSpeedMatch
private static Travelfun GetBestSpeedMatch(ICollection<Travelfun> speeds)
{
speeds = speeds.OrderBy(t => t.TimeBeforeNeedToSend).ToList();
if (!speeds.Any(x => x.TimeBeforeNeedToSend.TotalSeconds > AutoFindMinimumAmountOfSecondsLeft))
{
return speeds.OrderByDescending(x => x.TimeBeforeNeedToSend).FirstOrDefault();
}
else
{
return speeds.FirstOrDefault(x => x.TimeBeforeNeedToSend.TotalSeconds > AutoFindMinimumAmountOfSecondsLeft);
}
}
示例15: GetHighestCardInSuit
protected Card GetHighestCardInSuit(ICollection<Card> cards, CardSuit suit)
{
return cards.OrderByDescending(c => c.GetValue())
.FirstOrDefault(c => c.Suit == suit);
}