本文整理汇总了C#中Collection.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# Collection.OrderBy方法的具体用法?C# Collection.OrderBy怎么用?C# Collection.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection.OrderBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateTryParseAll
public void ValidateTryParseAll()
{
IEnumerable<string> stringVals;
Collection<string> strColl = new Collection<string>();
strColl.Add("1"); strColl.Add("2");
stringVals = strColl.OrderBy(a => a);
IList<int> resultInt;
Assert.IsTrue(Parser.TryParseAll(stringVals, out resultInt));
Assert.AreEqual(1, resultInt.ElementAt(0));
Assert.AreEqual(2, resultInt.ElementAt(1));
strColl.Clear();
strColl.Add("true"); strColl.Add("false");
stringVals = strColl.OrderBy(a => a);
IList<bool> resultBool;
Assert.IsTrue(Parser.TryParseAll(stringVals, out resultBool));
Assert.AreEqual(false, resultBool.ElementAt(0));
Assert.AreEqual(true, resultBool.ElementAt(1));
strColl.Clear();
strColl.Add("1.23"); strColl.Add("7.98");
stringVals = strColl.OrderBy(a => a);
IList<float> resultFloat;
Assert.IsTrue(Parser.TryParseAll(stringVals, out resultFloat));
Assert.AreEqual(1.23f, resultFloat.ElementAt(0));
Assert.AreEqual(7.98f, resultFloat.ElementAt(1));
}
示例2: ValidateParseAll
public void ValidateParseAll()
{
IEnumerable<string> stringVals;
Collection<string> strColl = new Collection<string>();
strColl.Add("1"); strColl.Add("2");
stringVals = strColl.OrderBy(a => a);
IEnumerable<int> resultInt = Parser.ParseAll<int>(stringVals);
Assert.AreEqual(1, resultInt.ElementAt(0));
Assert.AreEqual(2, resultInt.ElementAt(1));
}
示例3: SortItems
public static Collection<Dictionary<String, String>> SortItems(Collection<Dictionary<String, String>> unsortedItems, String key)
{
var orderedlist = unsortedItems.OrderBy(k => k[key]);
var sortedItems = new Collection<Dictionary<String, String>>();
foreach (Dictionary<String, String> item in orderedlist)
{
sortedItems.Add(item);
}
return sortedItems;
}
示例4: Main
public static void Main()
{
ICollection<Student> students = new Collection<Student>()
{
new Student("Samson", "Weaver", "QQK01GRD3E"),
new Student("Oren", "Alston", "SEC56MNQ9L"),
new Student("Hamish", "Spears", "RXL23WN5FL"),
new Student("Chester", "Luna", "FQJ10XOGMR"),
new Student("Tyrone", "Burris", "EHG52ZP0PR"),
new Student("Palmer", "Reed", "ITF39VMIGN"),
new Student("Fritz", "Weber", "LFZ54BJ4BR"),
new Student("Nero", "Romero", "VVG90AH2PF"),
new Student("Giacomo", "Stein", "OVH15YV4MO"),
new Student("Merrill", "Baxter", "PZV0KEU0GS")
};
var sortedStudents = students.OrderBy(s => s.FacultyNumber);
ICollection<Worker> workers = new Collection<Worker>()
{
new Worker("Urielle", "Dorsey", 96.56m, 4),
new Worker("Haley", "Keller", 79.51m, 4),
new Worker("Zenia", "Pena", 14.76m, 3),
new Worker("MacKensie", "Bean", 42.71m, 5),
new Worker("Rhea", "Hood", 9.33m, 3),
new Worker("Caryn", "Figueroa", 74.21m, 8),
new Worker("Charde", "Peterson", 89.30m, 8),
new Worker("Sylvia", "Gonzalez", 65.00m, 6),
new Worker("Catherine", "Bishop", 90.58m, 7),
new Worker("Ramona", "King", 18.02m, 8),
};
var sortedWorkers = workers.OrderByDescending(w => w.MoneyPerHour());
// check data validity here
foreach (var worker in workers)
{
//Console.WriteLine(worker);
}
var allHumans = new List<Human>(students.Count + workers.Count);
allHumans.AddRange(students);
allHumans.AddRange(workers);
var sortedHumans = allHumans.OrderBy(h => h.FirstName).ThenBy(h => h.LastName);
foreach (var human in sortedHumans)
{
Console.WriteLine(human);
}
}
示例5: AwakeningIndex
public async Task AwakeningIndex()
{
try
{
if((await this.User()).Roles.FirstOrDefault(c => c.Role.Name == "Admin") != null )
{
var list = await db.Users.ToListAsync();
var Retreaters = list.Where( c => c.Retreater == true );
var Staffers = list.Where( c => c.Staffer == true );
var RetreatersPending = list.Where( c => c.RetreaterPending == true );
var StaffersPending = list.Where( c => c.StafferPending == true );
var RetreatersView = new Collection<UserView>();
foreach ( var item in Retreaters )
{
RetreatersView.Add( new UserView( item ) );
}
var StaffersView = new Collection<UserView>();
foreach ( var item in Staffers )
{
StaffersView.Add( new UserView( item ) );
}
var RetreatersPendingView = new Collection<UserView>();
foreach ( var item in RetreatersPending )
{
RetreatersPendingView.Add( new UserView( item ) );
}
var StaffersPendingView = new Collection<UserView>();
foreach ( var item in StaffersPending )
{
StaffersPendingView.Add( new UserView( item ) );
}
var SortedRetreaters = RetreatersView.OrderBy( m => m.Personal.FirstName );
var SortedStaffers = StaffersView.OrderBy( m => m.Personal.FirstName );
var SortedRetreatersPending = RetreatersPendingView.OrderBy( m => m.Personal.FirstName );
var SortedStaffersPending = StaffersPendingView.OrderBy( m => m.Personal.FirstName );
Clients.Caller.awakeningRetreaters( SortedRetreaters );
Clients.Caller.awakeningStaffers( SortedStaffers );
Clients.Caller.awakeningRetreatersPending( SortedRetreatersPending );
Clients.Caller.awakeningStaffersPending( SortedStaffersPending );
}
else
{
Clients.Caller.errorBack( "Unauthorized Access" );
}
}
catch(Exception e)
{
Clients.Caller.errorBack(e);
}
}
示例6: FindPath
public static List<Point> FindPath(int[,] field, Point start, Point goal)
{
//step 1
var closedSet = new Collection<PathNode>();
var openSet = new Collection<PathNode>();
//step 2
PathNode startNode = new PathNode()
{
Position = start,
CameFrom = null,
PathLengthFromStart = 0,
HeuristicEstimatePathLength = GetHeuristicPathLength(start, goal)
};
openSet.Add(startNode);
while (openSet.Count > 0)
{
//step 3
var currentNode = openSet.OrderBy(node =>
node.EstimateFullPathLength).First();
//step 4.
if (currentNode.Position == goal)
return GetPathForNode(currentNode);
//step 5.
openSet.Remove(currentNode);
closedSet.Add(currentNode);
//step 6.
foreach (var neighbourNode in GetNeighbours(currentNode, goal, field))
{
//step 7.
if (closedSet.Count(node => node.Position == neighbourNode.Position) > 0)
continue;
var openNode = openSet.FirstOrDefault(node =>
node.Position == neighbourNode.Position);
//step 8.
if (openNode == null)
openSet.Add(neighbourNode);
else
if (openNode.PathLengthFromStart > neighbourNode.PathLengthFromStart)
{
//step 9.
openNode.CameFrom = currentNode;
openNode.PathLengthFromStart = neighbourNode.PathLengthFromStart;
}
}
}
//step 10.
return null;
}
示例7: FindPath
public List<Cell> FindPath(GameField field, Cell start, Cell goal, Func<Cell, Cell, float> weightFunc = null)
{
var closedSet = new Collection<PathNode>();
var openSet = new Collection<PathNode>();
PathNode startNode = new PathNode()
{
Position = start,
CameFrom = null,
PathLengthFromStart = 0,
HeuristicEstimatePathLength = GetHeuristicPathLength(start, goal)
};
openSet.Add(startNode);
while (openSet.Count > 0)
{
var currentNode = openSet.OrderBy(node =>
node.EstimateFullPathLength).First();
if (currentNode.Position == goal)
return GetPathForNode(currentNode);
openSet.Remove(currentNode);
closedSet.Add(currentNode);
foreach (var neighbourNode in GetNeighbours(currentNode, goal, field, weightFunc))
{
if (closedSet.Count(node => node.Position == neighbourNode.Position) > 0)
continue;
var openNode = openSet.FirstOrDefault(node =>
node.Position == neighbourNode.Position);
if (openNode == null)
openSet.Add(neighbourNode);
else
if (openNode.PathLengthFromStart > neighbourNode.PathLengthFromStart)
{
openNode.CameFrom = currentNode;
openNode.PathLengthFromStart = neighbourNode.PathLengthFromStart;
}
}
}
return null;
}
示例8: VerifyApiDescriptions
public static void VerifyApiDescriptions(Collection<ApiDescription> apiDescriptions, List<object> expectedResults)
{
Assert.Equal(expectedResults.Count, apiDescriptions.Count);
ApiDescription[] sortedDescriptions = apiDescriptions.OrderBy(description => description.ID).ToArray();
object[] sortedExpectedResults = expectedResults.OrderBy(r =>
{
dynamic expectedResult = r;
HttpMethod expectedHttpMethod = expectedResult.HttpMethod;
string expectedRelativePath = expectedResult.RelativePath;
return expectedHttpMethod + expectedRelativePath;
}).ToArray();
for (int i = 0; i < sortedDescriptions.Length; i++)
{
dynamic expectedResult = sortedExpectedResults[i];
ApiDescription matchingDescription = sortedDescriptions[i];
Assert.Equal(expectedResult.HttpMethod, matchingDescription.HttpMethod);
Assert.Equal(expectedResult.RelativePath, matchingDescription.RelativePath);
Assert.Equal(expectedResult.HasRequestFormatters, matchingDescription.SupportedRequestBodyFormatters.Count > 0);
Assert.Equal(expectedResult.HasResponseFormatters, matchingDescription.SupportedResponseFormatters.Count > 0);
Assert.Equal(expectedResult.NumberOfParameters, matchingDescription.ParameterDescriptions.Count);
}
}
示例9: GetLatestTelemetry
public async Task<IEnumerable<Telemetry>> GetLatestTelemetry(string deviceId)
{
var storageConnectionString = _settings.StorageConnectionString;
var table = await AzureTableStorageHelper.GetTableAsync(storageConnectionString, _settings.TelemetryTableName);
var startTime = DateTimeOffset.Now.AddSeconds(-TimeOffsetInSeconds).DateTime;
var deviceFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, deviceId);
var timestampFilter = TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThanOrEqual, startTime);
var filter = TableQuery.CombineFilters(deviceFilter, TableOperators.And, timestampFilter);
TableQuery<TelemetryEntity> query = new TableQuery<TelemetryEntity>()
.Where(filter)
.Take(MaxRecordsToReceive)
.Select(new[] { "sensor11", "sensor14", "sensor15", "sensor9" });
var result = new Collection<Telemetry>();
var entities = table.ExecuteQuery(query)
.OrderByDescending(x => x.Timestamp)
.Take(MaxRecordsToSend);
foreach (var entity in entities)
{
var telemetry = new Telemetry
{
DeviceId = entity.PartitionKey,
RecordId = entity.RowKey,
Timestamp = entity.Timestamp.DateTime,
Sensor1 = Math.Round(double.Parse(entity.sensor11)),
Sensor2 = Math.Round(double.Parse(entity.sensor14)),
Sensor3 = Math.Round(double.Parse(entity.sensor15)),
Sensor4 = Math.Round(double.Parse(entity.sensor9))
};
result.Add(telemetry);
}
return result.OrderBy(x => x.Timestamp);
}
示例10: cmdgo_Click
private void cmdgo_Click(object sender, EventArgs e)
{
// maybe only random somekeys
Collection<Game> final = new Collection<Game>();
Collection<Game> initial = new Collection<Game>();
bool onlysteamlinked = (chkaddsteamlink.Enabled && chkaddsteamlink.Checked && chkignorenotbindedgame.Checked);
foreach (Game g in col2export) if ((onlysteamlinked && g.SteamId > 0) || !onlysteamlinked) initial.Add(g);
int maxrandomkey = Convert.ToInt32(txtrandomatmostkeys.Value);
if (chkrandommaxxkey.Checked && (col2export.Count > maxrandomkey))
{
Collection<Game> final2 = new Collection<Game>();
while (final2.Count < maxrandomkey)
{
Game nextgame = initial[new Random().Next(initial.Count())];
if (!final2.Contains(nextgame)) final2.Add(nextgame);
}
foreach (Game g in final2.OrderBy(g => g.Text).ToList()) final.Add(g);
}
else final = initial;
txtout.Text = txtintro.Text + Environment.NewLine;
foreach(Game g in final)
{
if ((chkignorenobal.Checked && g.KeysNotGiven > 0) || !chkignorenobal.Checked)
{
string newline = txtemotestart.Text;
string gamename = g.Text.Trim();
if (chkaddsteamlink.Enabled && chkaddsteamlink.Checked && g.SteamId > 0)
{
if (!chksteamincludedformat.Checked) gamename += " " + g.SteamApp.SteamAppUrl;
else gamename = string.Format("[URL={0}]{1}[/URL]", g.SteamApp.SteamAppUrl, gamename);
}
if (chkaddgamebalance.Checked)
{
string bal = g.KeysNotGiven.ToString();
if (chkavlformat1.Checked)
if (chkavlatstart.Checked) bal += " X ";
else bal = " X " + bal;
else if (chkavlformat2.Checked) bal = " [" + bal + "] ";
if (chkavlformat3.Checked)
{
if (chkrepeatcustom.Enabled && chkrepeatcustom.Checked)
{
bal = "";
for (int k = 0; k < g.KeysNotGiven; k++) bal += txtavlcustomformat.Text;
}
else bal = txtavlcustomformat.Text.Replace("%t", bal);
}
if (chkavlatstart.Checked) newline += bal;
newline += (gamename + txtaftergamename.Text);
if (chkavlatend.Checked) newline += bal;
}
else newline += gamename + txtaftergamename.Text;
txtout.Text += newline + txtemoteend.Text + Environment.NewLine; ;
}
}
txtout.Text += Environment.NewLine + txtend.Text;
if (chktimestamp.Checked) txtout.Text += Environment.NewLine + txttimestamp.Text.Replace("%t", DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString());
if (chkaddappinfo.Checked)
txtout.Text += Environment.NewLine + "[i]This list is cheerfully powered by " + App.Name + " v" + App.Version + ", created by AW[/i]";
if (chkreplaceclipboard.Checked) Functions.CliboardSafeTextSet(txtout.Text);
cmdcopy.Enabled = true;
}
示例11: GetSeniorEmployees
public Employee GetSeniorEmployees(Collection<Employee> employees)
{
if (employees == null || employees.Count == 0)
{
return null;
}
return employees.OrderBy(e => e.DateHired).FirstOrDefault();
}
示例12: ParseRawBlockGroups
//.........这里部分代码省略.........
{
var numberOfSubBlocks = blockType & 0x0f;
//C2 11 15 => [offset 0x11, width 1], [offset 15, width]
var tempCollection = new List<RawShapeBlock>();
for (int i = 0; i < numberOfSubBlocks; i++)
{
var nextByte = imageBytes[offset + 1];
var a = ((nextByte >> 4) | (0x1 << 4)) << 1;
var b = ((nextByte & 0xf) | (0x1 << 4)) << 1;
tempCollection.Add(new RawShapeBlock(b, a));
offset++;
}
offset++;
rawShapeBlocksGroups.Add(new RawShapeBlocksGroup(tempCollection, rowIndex++));
continue;
}
if (blockType >> 4 == 0x8)
{
var numberOfSubBlocks = blockType & 0x0f;
var tempCollection = new List<RawShapeBlock>();
for (var i = 0; i < numberOfSubBlocks; i++)
{
var nextByte = imageBytes[offset + 1];
var a = (nextByte >> 4);
var b = (0x0f & nextByte);
tempCollection.Add(new RawShapeBlock(b, a));
offset++;
}
rawShapeBlocksGroups.Add(new RawShapeBlocksGroup(tempCollection, rowIndex++));
offset++;
continue;
}
//new
if (blockType >> 4 == 0x9)
{
var numberOfSubBlocks = blockType & 0x0f;
var tempCollection = new List<RawShapeBlock>();
for (var i = 0; i < numberOfSubBlocks; i++)
{
var nextByte = imageBytes[offset + 1];
var b = (nextByte >> 4);
var a = (0x0f & nextByte);
tempCollection.Add(new RawShapeBlock(b, a));
offset++;
}
rawShapeBlocksGroups.Add(new RawShapeBlocksGroup(tempCollection, rowIndex++));
offset++;
continue;
}
if (blockType > 111)
{
//break;
Helper.DumpArray(imageBytes, offset - 5, 128);
throw new Exception("wrong block type. Dump:\n ");
}
//ordinary processing
var bytesInBlock = blockType * 2 + 1;
var emptyCollection = new List<RawShapeBlock>();
for (int k = 0; k < blockType * 2; k += 2)
{
emptyCollection.Add(new RawShapeBlock(
offsetx: imageBytes[offset + k + 1],
length: imageBytes[offset + k + 2]));
}
rawShapeBlocksGroups.Add(new RawShapeBlocksGroup(emptyCollection, rowIndex++));
offset += bytesInBlock;
}
var blockStatistics = collectionOfBlockTypes.OrderBy(it => it).GroupBy(it => it).ToDictionary(it => it.Key, it => it.Count());
PrintBlocksSTatistics(blockStatistics);
return rawShapeBlocksGroups.ToArray();
}
示例13: RolesIndex
public async Task RolesIndex()
{
try
{
if ( ( await this.User() ).Roles.FirstOrDefault( c => c.Role.Name == "Admin" ) != null )
{
var Roles = db.Roles.ToList();
var RolesView = new Collection<RoleView>();
foreach ( var role in Roles )
{
RolesView.Add( new RoleView( role ) );
}
var SortedRoles = RolesView.OrderBy( c => c.Name );
Clients.Caller.roleIndexBack( SortedRoles );
}
else
{
Clients.Caller.errorBack( "Unauthorized Access" );
}
}
catch ( Exception e )
{
Clients.Caller.errorBack( e );
}
}
示例14: MapGangwayLocations
/// <summary>
/// Maps the gangway locations.
/// </summary>
/// <param name="dataReader">The data reader.</param>
/// <returns>The collection of gangway location</returns>
private static async Task<ICollection<GangwayLocation>> MapGangwayLocations(SqlDataReader dataReader)
{
var gangwayLocations = new Collection<GangwayLocation>();
if (dataReader != null)
{
while (await dataReader.ReadAsync())
{
var gangwayLocation = new GangwayLocation
{
LocationId = dataReader.Int32Field(LocationId).ToString(),
LocationTypeId = dataReader.ByteField(LocationTypeId).ToString(),
Name = dataReader.StringField(Name)
};
gangwayLocations.Add(gangwayLocation);
}
}
return gangwayLocations.OrderBy(a => a.Name).ToList();
}
示例15: RetreaterFees
public async Task<ActionResult> RetreaterFees()
{
var users = await db.Users.ToListAsync();
ICollection<UserView> Users = new Collection<UserView>();
foreach(var user in users)
{
if(user.RetreaterPending || user.Retreater)
Users.Add(new UserView(user));
}
var OrderedUsers = Users.OrderBy(c=>c.ApplicationStamp);
return View( OrderedUsers );
}