本文整理汇总了C#中Library.List.Sort方法的典型用法代码示例。如果您正苦于以下问题:C# List.Sort方法的具体用法?C# List.Sort怎么用?C# List.Sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Library.List
的用法示例。
在下文中一共展示了List.Sort方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
private void Update()
{
this.NotifyPropertyChanged(nameof(this.Name));
{
var tempList = new List<SignatureTreeViewModel>();
foreach (var item in _value.Children)
{
tempList.Add(new SignatureTreeViewModel(this, item));
}
tempList.Sort((x, y) =>
{
int c = x.Value.LinkItem.Signature.CompareTo(y.Value.LinkItem.Signature);
if (c != 0) return c;
return x.GetHashCode().CompareTo(y.GetHashCode());
});
_children.Clear();
_children.AddRange(tempList);
}
}
示例2: Process
/// <summary>
/// Region growing to encode the source image data.
/// </summary>
/// <param name="locationPool"></param>
/// <param name="maximumDistance"></param>
/// <param name="type"></param>
/// <returns></returns>
private static HashSet<Region> Process(LocationPool locationPool, double maximumDistance, RegionType type)
{
HashSet<Region> result = new HashSet<Region>();
List<Location> todoList = new List<Location>();
//let's process pixels into regions
Region region = null;
HashSet<Location> alreadyChecked = new HashSet<Location>();
while (!locationPool.Empty())
{
alreadyChecked.Clear();
Location seed = locationPool.RandomLocation();
//Console.WriteLine("Have seed " + seed);
if (type == RegionType.MonoRegion)
{
region = new MonoRegion();
}
else if (type == RegionType.MultiColorRegion)
{
MultiColorRegion multiColorRegion = new MultiColorRegion(maximumDistance);
region = multiColorRegion;
}
region.Add(seed);
region.Origin = seed.Point;
seed.Region = region;
locationPool.SetMarked(seed);
alreadyChecked.Add(seed);
AddNeighbors(seed, todoList, alreadyChecked);
todoList.Sort((x, y) => (int)(SxzColor.GetColorDistance(seed.Color, x.Color) - SxzColor.GetColorDistance(seed.Color, y.Color)));
int sortCounter = 0;
//inner loop
while (todoList.Count != 0)
{
//Console.WriteLine("Unmarked total " + locationPool.Unmarked.Count + " and todolist total " + todoList.Count);
seed = todoList[0];
todoList.RemoveAt(0);
sortCounter++;
if (seed.Marked)
{
throw new Exception("Location already marked!");
}
if (!region.IsValid(seed))
{
//we can process non-adjacent pixels by adding neighbors here and sorting before returning but limit the distance from an already
//validated location
continue;
}
//Console.WriteLine("Parsed pixel " + seed);
//we have a winner!
region.Add(seed);
locationPool.SetMarked(seed);
AddNeighbors(seed, todoList, alreadyChecked);
//if (todoList.Count < 1000)
if (todoList.Count < 1000 || sortCounter > 1000)
{
//let's limit the number to be sorted for performance sake
todoList.Sort((x1, y1) => (int)(SxzColor.GetColorDistance(seed.Color, x1.Color) - SxzColor.GetColorDistance(seed.Color, y1.Color)));
sortCounter = 0;
}
}
result.Add(region);
}
return result;
}
示例3: SetupUILanguage
private void SetupUILanguage()
{
string selected = null;
List<string> list = new List<string>();
string configuredLangId = OMLSettings.UILanguage;
foreach (var availableCulture in I18n.AvailableCultures)
{
string name = availableCulture.TextInfo.ToTitleCase(availableCulture.NativeName);
if (string.CompareOrdinal(availableCulture.Name, configuredLangId) == 0)
{
selected = name;
}
list.Add(name);
}
list.Sort((a, b) => string.Compare(a, b, true, Thread.CurrentThread.CurrentCulture));
list.Insert(0, "Use system language");
if (string.IsNullOrEmpty(selected)) selected = list[0];
_uiLanguage.Options = list;
_uiLanguage.Chosen = selected;
}
示例4: Monitor
public bool? Monitor(params object[] data)
{
// TODO: move partially up
byte backgroundCycles = Config.BackgroundCycles;
doBackgroundPremeasure = backgroundCycles != 0;
Graph.MeasureGraph g;
switch (pState) {
case ProgramStates.Ready:
if (SomePointsUsed) {
//Order is important here!!!! Underlying data update before both matrix formation and measure mode init.
g = Graph.MeasureGraph.Instance;
g.ResetForMonitor();
//var peaks = g.PreciseData.GetUsed();
//already filtered in ResetForMonitor()
var peaks = g.PreciseData;
#warning matrix is formed too early
// TODO: move matrix formation to manual operator actions
// TODO: parallelize matrix formation, flag on completion
// TODO: duplicates
peaksForMatrix = peaks.GetWithId();
if (peaksForMatrix.Count > 0) {
// To comply with other processing order (and saved information)
peaksForMatrix.Sort(PreciseEditorData.ComparePreciseEditorDataByPeakValue);
matrix = new Matrix(Config.LoadLibrary(peaksForMatrix));
// What do with empty matrix?
if (matrix != null)
matrix.Init();
else {
OnLog("Error in peak data format or duplicate substance.");
return null;
}
} else
matrix = null;
// TODO: feed measure mode with start shift value (really?)
short? startShiftValue = 0;
{
var co = g.CommonOptions;
var temp = new MeasureMode.Precise.Monitor(Config.MIN_STEP, Config.MAX_STEP,
// TODO: getWithId()
peaks,
co.befTimeReal, co.iTimeReal, co.eTimeReal,
co.ForwardTimeEqualsBeforeTime ? co.befTimeReal : co.fTimeReal, co.bTimeReal,
(p, peak) => g.updateGraphDuringPreciseMeasure(p, peak, Counts),
g.updateGraphAfterPreciseMeasure,
Config.Iterations, Config.TimeLimit,
// TODO: move extra data into checker
Config.CheckerPeak, Config.CheckerPeak == null ? null : startShiftValue, Config.AllowedShift);
temp.SaveResults += (s, e) => {
Config.autoSaveMonitorSpectrumFile(LabelNumber);
if (LabelNumber.HasValue)
LabelNumber = null;
};
temp.Finalize += (s, e) => Config.finalizeMonitorFile();
// how to unsubscribe?
//realizer.MeasureSend += (s, e) => temp.NextMeasure(e.Value);
CurrentMeasureMode = temp;
}
if (doBackgroundPremeasure) {
initMeasure(ProgramStates.WaitBackgroundMeasure);
background = new FixedSizeQueue<List<long>>(backgroundCycles);
// or maybe Enumerator realization: one item, always recounting (accumulate values)..
g.GraphDataModified += NewBackgroundMeasureReady;
} else {
initMeasure(ProgramStates.Measure);
g.GraphDataModified += NewMonitorMeasureReady;
}
return true;
} else {
OnLog("No points for monitor mode measure.");
return null;
}
case ProgramStates.BackgroundMeasureReady:
// set background end label
LabelNumber = 0;
g = Graph.MeasureGraph.Instance;
g.GraphDataModified -= NewBackgroundMeasureReady;
backgroundResult = background.Aggregate(Summarize);
for (int i = 0; i < backgroundResult.Count; ++i) {
// TODO: check integral operation behaviour here
backgroundResult[i] /= backgroundCycles;
}
setProgramStateWithoutUndo(ProgramStates.Measure);
g.GraphDataModified += NewMonitorMeasureReady;
return false;
case ProgramStates.Measure:
// set label
LabelNumber = (int)data[0];
return false;
default:
// wrong state, strange!
return null;
}
//.........这里部分代码省略.........
示例5: ConnectionsManagerThread
private void ConnectionsManagerThread()
{
Stopwatch connectionCheckStopwatch = new Stopwatch();
connectionCheckStopwatch.Start();
Stopwatch refreshStopwatch = new Stopwatch();
Stopwatch pushBlockDiffusionStopwatch = new Stopwatch();
pushBlockDiffusionStopwatch.Start();
Stopwatch pushBlockUploadStopwatch = new Stopwatch();
pushBlockUploadStopwatch.Start();
Stopwatch pushBlockDownloadStopwatch = new Stopwatch();
pushBlockDownloadStopwatch.Start();
Stopwatch pushMetadataUploadStopwatch = new Stopwatch();
pushMetadataUploadStopwatch.Start();
Stopwatch pushMetadataDownloadStopwatch = new Stopwatch();
pushMetadataDownloadStopwatch.Start();
for (; ; )
{
Thread.Sleep(1000);
if (this.State == ManagerState.Stop) return;
var connectionCount = 0;
lock (this.ThisLock)
{
connectionCount = _connectionManagers.Count;
}
if (connectionCount > ((this.ConnectionCountLimit / 3) * 1)
&& connectionCheckStopwatch.Elapsed.TotalMinutes >= 5)
{
connectionCheckStopwatch.Restart();
var nodeSortItems = new List<NodeSortItem>();
lock (this.ThisLock)
{
foreach (var connectionManager in _connectionManagers)
{
nodeSortItems.Add(new NodeSortItem()
{
Node = connectionManager.Node,
Priority = _messagesManager[connectionManager.Node].Priority,
LastPullTime = _messagesManager[connectionManager.Node].LastPullTime,
});
}
}
nodeSortItems.Sort((x, y) =>
{
int c = x.Priority.CompareTo(y.Priority);
if (c != 0) return c;
return x.LastPullTime.CompareTo(y.LastPullTime);
});
foreach (var node in nodeSortItems.Select(n => n.Node).Take(1))
{
ConnectionManager connectionManager = null;
lock (this.ThisLock)
{
connectionManager = _connectionManagers.FirstOrDefault(n => n.Node == node);
}
if (connectionManager != null)
{
try
{
lock (this.ThisLock)
{
this.RemoveNode(connectionManager.Node);
}
connectionManager.PushCancel();
Debug.WriteLine("ConnectionManager: Push Cancel");
}
catch (Exception)
{
}
this.RemoveConnectionManager(connectionManager);
}
}
}
if (!refreshStopwatch.IsRunning || refreshStopwatch.Elapsed.TotalSeconds >= 30)
{
refreshStopwatch.Restart();
// トラストにより必要なMetadataを選択し、不要なMetadataを削除する。
ThreadPool.QueueUserWorkItem((object wstate) =>
{
if (_refreshThreadRunning) return;
_refreshThreadRunning = true;
//.........这里部分代码省略.........