本文整理汇总了C#中Model.List.Sort方法的典型用法代码示例。如果您正苦于以下问题:C# List.Sort方法的具体用法?C# List.Sort怎么用?C# List.Sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model.List
的用法示例。
在下文中一共展示了List.Sort方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
internal static string Build(List<TestAttribute> Categories)
{
string source = "";
var list = new List<string>();
Categories
.ToList()
.ForEach(c => list.Add(c.GetName()));
list.Sort();
var catParams = new string[] {
ExtentFlag.GetPlaceHolder("testCategory"),
ExtentFlag.GetPlaceHolder("testCategoryU")
};
list.ForEach(c =>
{
var catValues = new string[] {
c,
c.ToLower().Replace(" ", "")
};
source += SourceBuilder.Build(CategoryFilterHtml.GetOptionSource(), catParams, catValues);
});
return source;
}
示例2: SortTest
public void SortTest()
{
var episodes = new List<TvdbEpisode>();
episodes.Add(new TvdbEpisode { SeasonNumber = 2, EpisodeNumber = 1 });
episodes.Add(new TvdbEpisode { SeasonNumber = 1, EpisodeNumber = 1 });
episodes.Add(new TvdbEpisode { SeasonNumber = 1, EpisodeNumber = 5 });
episodes.Add(new TvdbEpisode { SeasonNumber = 3, EpisodeNumber = 12 });
episodes.Add(new TvdbEpisode { SeasonNumber = 2, EpisodeNumber = 12 });
episodes.Sort(new TvEpisodeComparer());
Assert.Equal(1, episodes[0].SeasonNumber);
Assert.Equal(1, episodes[0].EpisodeNumber);
Assert.Equal(1, episodes[1].SeasonNumber);
Assert.Equal(5, episodes[1].EpisodeNumber);
Assert.Equal(2, episodes[2].SeasonNumber);
Assert.Equal(1, episodes[2].EpisodeNumber);
Assert.Equal(2, episodes[3].SeasonNumber);
Assert.Equal(12, episodes[3].EpisodeNumber);
Assert.Equal(3, episodes[4].SeasonNumber);
Assert.Equal(12, episodes[4].EpisodeNumber);
}
示例3: CategoryViewer
public CategoryViewer(Category category)
{
Title = WindowTitle = "Category: " + category.Name;
this.category = category;
InitializeComponent();
Header.DataContext = category;
posts = new List<Post>(category.Posts);
posts.Sort(delegate(Post x, Post y) { return x.Modified.CompareTo(y.Modified); });
PostsView.ItemsSource = posts;
}
示例4: GetRange
public List<Tweet> GetRange(int count, decimal lastId)
{
List<Tweet> displayTweets = new List<Tweet>();
displayTweets = _tweets.Where(tweet => tweet.Id > lastId).ToList<Tweet>();
if (displayTweets.Count > count)
{
displayTweets = displayTweets.GetRange(0, count);
}
displayTweets.Sort(new TwitterComparer());
return displayTweets;
}
示例5: buildOptions
public static string buildOptions(List<string> Categories)
{
string source = "";
Categories.Sort();
foreach (string c in Categories) {
source += SourceBuilder.BuildSimple(CategoryHtml.GetOptionSource(), new string[] { ExtentFlag.GetPlaceHolder("testCategory"), ExtentFlag.GetPlaceHolder("testCategoryU") }, new string[] { c, c.ToLower().Replace(" ", "") });
}
return source;
}
示例6: ListaPaises
public static List<string> ListaPaises()
{
List<string> ListaCultura = new List<string>();
CultureInfo[] SelecionarCultureInfo = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
foreach (CultureInfo SelecionarCultura in SelecionarCultureInfo)
{
RegionInfo SelecionarRegionInfo = new RegionInfo(SelecionarCultura.LCID);
if (!(ListaCultura.Contains(SelecionarRegionInfo.DisplayName)))
{
ListaCultura.Add(SelecionarRegionInfo.DisplayName);
}
}
ListaCultura.Sort();
return ListaCultura;
}
示例7: GetRandomInterval
/// <summary>
/// Return a pair of random integers, where the first is always lower than
/// the second, and there is not more than maxDistance between the returned integers.
/// Keeping this interval close is because the main usecase is a musical interval test
/// where a large distance would not help with aural training.
/// It helps if the Random passed in has been used in previous calls, to help entropy.
/// </summary>
public List<int> GetRandomInterval(int lowerLimit, int upperLimit, int maxDistance, Random rand) {
if (lowerLimit.Equals(upperLimit)) {
return new List<int> {lowerLimit, upperLimit};
}
const int MaxIterations = 100;
var lowerAndUpperLimit = new List<int>{rand.Next(lowerLimit,upperLimit)};
var nextNote = rand.Next(lowerLimit, upperLimit);
var count = 0;
while (lowerAndUpperLimit[0] == nextNote || System.Math.Abs(lowerAndUpperLimit[0] - nextNote) > maxDistance) {
if (count++ > MaxIterations) {
throw new Exception("Too many iterations");
}
nextNote = rand.Next(lowerLimit, upperLimit);
}
lowerAndUpperLimit.Add(nextNote);
lowerAndUpperLimit.Sort();
return lowerAndUpperLimit;
}
示例8: buildOptions
public static string buildOptions(List<string> Categories)
{
string source = "";
Categories.Sort();
var catFlags = new string[] {
ExtentFlag.GetPlaceHolder("testCategory"),
ExtentFlag.GetPlaceHolder("testCategoryU")
};
Categories.ForEach(c =>
{
var catValues = new string[] {
c,
c.ToLower().Replace(" ", "")
};
source += SourceBuilder.Build(CategoryHtml.GetOptionSource(), catFlags, catValues);
});
return source;
}
示例9: Sort
/// <summary>
/// Sorts the specified list.
/// </summary>
/// <param name="list">The list.</param>
/// <param name="sortExpression">The sort expression.</param>
/// <param name="sortDirection">The sort direction.</param>
public static List<Resume> Sort(List<Resume> list, string sortExpression,
string sortDirection)
{
if (!string.IsNullOrEmpty(sortExpression))
{
list.Sort(new ListSorter<Resume>(sortExpression));
}
if (sortDirection != null && sortDirection == "Desc")
{
list.Reverse();
}
return list;
}
示例10: OnLaunched
protected async override void OnLaunched(LaunchActivatedEventArgs e)
{
List<MyLine> listLines = new List<MyLine>();
//int minSize = 40;
//int maxSize = 2600;
int wordTopRange = 25;
StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile file = null;
if (!string.IsNullOrEmpty(e.Arguments))
{
try
{
OcrEngine ocrEngine = new OcrEngine(OcrLanguage.English);
file = await folder.GetFileAsync(e.Arguments);
ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync();
//if (imgProp.Height < minSize || imgProp.Height > maxSize || imgProp.Width < minSize || imgProp.Width > maxSize)
//{
// await WriteToFile(folder, file.Name + ".txt", "Image size must be > 40 and < 2600 pixel");
//}
//else
//{
WriteableBitmap bitmap = null;
using (IRandomAccessStream imgStream = await file.OpenAsync(FileAccessMode.Read))
{
bitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height);
bitmap.SetSource(imgStream);
}
// This main API call to extract text from image.
OcrResult ocrResult = await ocrEngine.RecognizeAsync((uint)bitmap.PixelHeight, (uint)bitmap.PixelWidth, bitmap.PixelBuffer.ToArray());
// If there is text.
if (ocrResult.Lines != null)
{
StringBuilder builder = new StringBuilder();
// loop over recognized text.
foreach (OcrLine line in ocrResult.Lines)
{
// Iterate over words in line.
foreach (OcrWord word in line.Words)
{
// sort the word line by line
bool isBelongToLine = false;
foreach (MyLine myLine in listLines)
{
// if line exist, add word to line
if (Between(myLine.lineNumber, word.Top - wordTopRange, word.Top + wordTopRange, true))
{
myLine.listWords.Add(word);
isBelongToLine = true;
break;
}
}
// if line does not exist, create new line, add word to line
if (isBelongToLine == false)
{
MyLine myLine = new MyLine();
myLine.lineNumber = word.Top;
myLine.listWords.Add(word);
listLines.Add(myLine);
}
// sort the word line by line
}
}
// sort the lines base on top position
listLines.Sort();
// return data line by line
foreach (MyLine myLine in listLines)
{
builder.Append(myLine.ToString());
}
await WriteToFile(folder, file.Name + ".txt", builder.ToString());
}
else // if no text
{
await WriteToFile(folder, file.Name + ".txt", "No Text");
}
//}
}
catch (Exception ex)
{
await WriteToFile(folder, file.Name + ".txt", "Exception");
}
App.Current.Exit();
}
//.........这里部分代码省略.........
示例11: AdminsList
public MvcHtmlString AdminsList(string userEmail)
{
var user = userRepository.Find(u => u.Email == userEmail);
var admins = redactorRepository.FindAll(r => r.UserId_Id == user.Id).GroupBy(u => u.Administrator_Id).Select(g => g.First()).ToList();
if (admins != null && admins.Count > 0)
{
List<string> adminsEmails = new List<string>();
foreach (var admin in admins)
{
var administrator = userRepository.Find(u => u.Id == admin.Administrator_Id);
adminsEmails.Add(administrator.Email);
}
StringBuilder builder = new StringBuilder();
adminsEmails.Sort();
foreach (var adminEmail in adminsEmails)
{
builder.AppendLine("<li>" + adminEmail + "</li>");
}
return new MvcHtmlString(builder.ToString());
}
return null;
}
示例12: SortViewModelsByDate
private void SortViewModelsByDate(List<NewsDetailsViewModel> newsDetailsViewModels)
{
newsDetailsViewModels.Sort((first, second) => second.PublicationDate.CompareTo(first.PublicationDate));
}
示例13: LoadParameterData
protected override void LoadParameterData()
{
String IDAttribute = XmlSchemaConstants.Display.Component.Id;
String NameAttribute = XmlSchemaConstants.Display.Component.Name;
String LinkIDAttribute = "LinkID";
IXPathNavigable iNavigator = myController.GetComponentAndChildren(SelectedID, linkType, 2, false, true);
XPathNavigator navigator = iNavigator.CreateNavigator();
//// Perform a CRC checksum on the data coming back, only update if it has changed
//MD5CryptoServiceProvider x = new MD5CryptoServiceProvider();
//Byte[] bs = System.Text.Encoding.UTF8.GetBytes(navigator.OuterXml);
//bs = x.ComputeHash(bs);
//System.Text.StringBuilder s = new System.Text.StringBuilder();
//foreach (Byte b in bs)
//{
// s.Append(b.ToString("x2").ToLower());
//}
//String newCrc = s.ToString();
DrawingUtility.SuspendDrawing(this);
//if (!crc.Equals(newCrc)) // otherwise update with the new data
{
//crc = newCrc;
this.Columns.Clear();
pairInformation = new List<ComponentPair>();
if (navigator.HasChildren)
{
Dictionary<String, int> rowNameToIndex = new Dictionary<String, int>();
nodeNameToID = new Dictionary<string, int>();
XPathNodeIterator listOfNodes = navigator.Select(String.Format("/Components/Component/Component"));
List<String> names = new List<String>();
foreach (XPathNavigator nodeNav in listOfNodes)
{
int nodeID = Int32.Parse(nodeNav.GetAttribute(IDAttribute, nodeNav.NamespaceURI));
String nodeName = nodeNav.GetAttribute(NameAttribute, nodeNav.NamespaceURI);
names.Add(nodeName);
nodeNameToID.Add(nodeName, nodeID);
}
names.Sort();
foreach (String aName in names)
{
int addedColumn = Columns.Add(aName, aName);
int addedRow = this.Rows.Add();
Rows[addedRow].HeaderCell.Value = aName;
rowNameToIndex.Add(aName, addedRow);
}
int fromID, toID;
int rowIndex, linkID;
String paramValue, columnName, rowName;
String linkString = "";
//now, form links.
foreach (XPathNavigator nodeNav in listOfNodes)
{
rowName = nodeNav.GetAttribute(NameAttribute, nodeNav.NamespaceURI);
fromID = Int32.Parse(nodeNav.GetAttribute(IDAttribute, nodeNav.NamespaceURI));
rowIndex = rowNameToIndex[rowName];
if (nodeNav.HasChildren)
{
XPathNodeIterator listOfChildren = nodeNav.Select("Component");
foreach (XPathNavigator childNav in listOfChildren)
{
columnName = childNav.GetAttribute(NameAttribute, childNav.NamespaceURI);
toID = Int32.Parse(childNav.GetAttribute(IDAttribute, childNav.NamespaceURI));
linkString = childNav.GetAttribute(LinkIDAttribute, childNav.NamespaceURI);
if (linkString != null && linkString != "")
{
linkID = Int32.Parse(linkString);
}
else
{
linkID = -1;
}
pairInformation.Add(new ComponentPair(rowName, columnName, linkID));
XPathNavigator pnav = childNav.SelectSingleNode("LinkParameters/Parameter");
if (pnav != null)
{
paramValue = pnav.GetAttribute("Value", pnav.NamespaceURI);
if (paramValue.Equals(""))
{
//.........这里部分代码省略.........