本文整理汇总了C#中System.Collections.Generic.List.Sort方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.List.Sort方法的具体用法?C# System.Collections.Generic.List.Sort怎么用?C# System.Collections.Generic.List.Sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.List
的用法示例。
在下文中一共展示了System.Collections.Generic.List.Sort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPartitions
/// <summary>
/// Gets a list of partitions on the xbox hard drive.
/// </summary>
public System.Collections.Generic.List<string> GetPartitions()
{
int oldTimeout = timeout; // sometimes hdd can be slow so we increase our timeout
timeout = 10000;
var List = new System.Collections.Generic.List<string>();
StatusResponse response = SendCommand("drivelist");
for (int i = 0; i < response.Message.Length; i++)
List.Add(response.Message[i] + ":\\");
List.Sort();
timeout = oldTimeout;
return List;
}
示例2: Random
public void Random()
{
BinaryTree<int> Tree = new BinaryTree<int>();
System.Collections.Generic.List<int> Values = new System.Collections.Generic.List<int>();
System.Random Rand = new System.Random();
for (int x = 0; x < 10; ++x)
{
int Value = Rand.Next();
Values.Add(Value);
Tree.Add(Value);
}
for (int x = 0; x < 10; ++x)
{
Assert.Contains(Values[x], Tree);
}
Values.Sort();
Assert.Equal(Values.ToString(x => x.ToString(), " "), Tree.ToString());
}
示例3: GetDecodeList
/// <summary>
/// 整理并解码点播链接
/// </summary>
/// <param name="lists"></param>
/// <returns></returns>
public static System.Collections.Generic.List<string> GetDecodeList(System.Collections.Generic.List<string> lists)
{
#region 整理并解码点播链接
var ends = new System.Collections.Generic.List<string>();
if (lists != null && lists.Count > 0)
{
for (var i = 0; i < lists.Count; i++)
{
var newurl = System.Web.HttpUtility.UrlDecode(lists[i]);
if (!string.IsNullOrEmpty(newurl))
{
if (newurl.StartsWith("magnet:?xt=urn:btih:"))
{
if (newurl.Contains("&"))
{
newurl = newurl.Split('&')[0] + string.Format("&dn=KCPlayer[{0}]", QualityHelper.GetHdsData(new System.Collections.Generic.List<string> { newurl }));
}
}
ends.Add(newurl);
}
}
if (ends.Count > 0)
{
try
{
ends.Sort();
}
// ReSharper disable EmptyGeneralCatchClause
catch
// ReSharper restore EmptyGeneralCatchClause
{
}
}
}
return ends;
#endregion
}
示例4: KeepLastXSubDirs
/// <summary>
/// Keeps the last X sub dirs.
/// </summary>
/// <param name="targetFolder">The target folder.</param>
/// <param name="amountToKeep">The amount to keep.</param>
/// <param name="buildLogDirectory">The build log directory.</param>
private void KeepLastXSubDirs(string targetFolder, int amountToKeep, string buildLogDirectory)
{
Log.Trace("Deleting Subdirs of {0}", targetFolder);
var sortNames = new System.Collections.Generic.List<string>();
const string dateFormat = "yyyyMMddHHmmssffffff";
foreach (var folder in Directory.GetDirectories(targetFolder))
{
if (folder != buildLogDirectory)
sortNames.Add(Directory.GetCreationTime(folder).ToString(dateFormat, CultureInfo.CurrentCulture) + folder);
}
sortNames.Sort();
var amountToDelete = sortNames.Count - amountToKeep;
for (var i = 0; i < amountToDelete; i++)
{
DeleteFolder(sortNames[0].Substring(dateFormat.Length));
sortNames.RemoveAt(0);
}
}
示例5: BindTags
private void BindTags()
{
System.Collections.Generic.List<string> col = new System.Collections.Generic.List<string>();
foreach (Post post in Post.Posts)
{
foreach (string tag in post.Tags)
{
if (!col.Contains(tag))
col.Add(tag);
}
}
col.Sort(delegate(string s1, string s2) { return String.Compare(s1, s2); });
foreach (string tag in col)
{
HtmlAnchor a = new HtmlAnchor();
a.HRef = "javascript:void(0)";
a.Attributes.Add("onclick", "AddTag(this)");
a.InnerText = tag;
phTags.Controls.Add(a);
}
}
示例6: OrderByType
void OrderByType()
{
if (_assets != null) {
var tmpList = new System.Collections.Generic.List<Object> (_assets);
tmpList.Sort ((asset0, asset1) => {
int result = asset0.GetType ().FullName.CompareTo (asset1.GetType ().FullName);
if (result == 0) {
result = asset0.ToString ().CompareTo (asset1.ToString ());
}
return result;
});
_assets = tmpList.ToArray ();
}
}
示例7: OrderBySize
void OrderBySize()
{
if (_assets != null) {
var tmpList = new System.Collections.Generic.List<Object> (_assets);
tmpList.Sort ((asset0, asset1) => Profiler.GetRuntimeMemorySize (asset1) - Profiler.GetRuntimeMemorySize (asset0));
_assets = tmpList.ToArray ();
}
}
示例8: OrderByName
void OrderByName()
{
if (_assets != null) {
var tmpList = new System.Collections.Generic.List<Object> (_assets);
tmpList.Sort ((asset0, asset1) => asset0.ToString ().CompareTo (asset1.ToString ()));
_assets = tmpList.ToArray ();
}
}
示例9: placeLG_Rooms_rand
public void placeLG_Rooms_rand(int minW, int maxW, int minH, int maxH, int numLG_Rooms)
{
int maxHorz = (int)Mathf.Floor(width / (maxW+6));
int maxVert = (int)Mathf.Floor(height / (maxH+6));
int maxNumLG_Rooms = maxHorz * maxVert;
numLG_Rooms = Mathf.Min(numLG_Rooms, maxNumLG_Rooms);
System.Collections.Generic.List<RandomRoom> tempLG_RoomList = new System.Collections.Generic.List<RandomRoom>();
RandomRoom theLG_Room;
for(int i = 0; i < numLG_Rooms; i++)
{
int xx = r.getIntInRange(0, width-maxW);
int yy = r.getIntInRange(0,height-maxH);
theLG_Room = new RandomRoom(xx,yy, minW, maxW, minH, maxH, r);
theLG_Room.garbage = r.getIntInRange(int.MinValue, int.MaxValue);
tempLG_RoomList.Add(theLG_Room);
//int widthDiff = maxW - theLG_Room.width;
//int heightDiff = maxH - theLG_Room.height
}
for(int j = 0; j < numLG_Rooms; j++)
{
theLG_Room = tempLG_RoomList[j];
Rect roomRect = new Rect(theLG_Room.x * tileWidth, theLG_Room.y * tileHeight, theLG_Room.width * tileWidth, theLG_Room.height * tileHeight);
Vector2 center = new Vector2(roomRect.x + Mathf.Floor(roomRect.width/2), roomRect.y + Mathf.Floor(roomRect.height/2));
roomCenterPoints.Add(center);
this.addLG_Room(theLG_Room);
rooms_sorted[center] = theLG_Room;
}//for
tempLG_RoomList.Sort(sortLG_Rooms);
//Using the data in the acutal level, figure out all the room connections
roomTree = new MinimumSpan(roomCenterPoints);
roomConnections = roomTree.createMinimumSpan();
}
示例10: Main
static void Main(string[] args)
{
System.Collections.Generic.List<Ofx.Document> documents = new System.Collections.Generic.List<Ofx.Document>();
string outputDirectory;
// check if a directory has been supplied
if ((System.IO.File.GetAttributes(args[0]) & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory)
{
outputDirectory = args[0];
// load each file in the directory if it is an ofx file
foreach (string filename in System.IO.Directory.GetFiles(args[0]))
{
System.IO.FileInfo info = new System.IO.FileInfo(filename);
if (System.String.Compare(info.Extension, ".ofx", true) == 0)
{
Ofx.Document file = new Ofx.Document(filename, "../../../external/SgmlReader/TestSuite/ofx160.dtd");
documents.Add(file);
}
}
}
else
{
System.IO.FileInfo inputFileInfo = new System.IO.FileInfo(args[0]);
outputDirectory = inputFileInfo.DirectoryName;
// load each argument as an ofx file
foreach (string filename in args)
{
Ofx.Document file = new Ofx.Document(filename, "../../../external/SgmlReader/TestSuite/ofx160.dtd");
documents.Add(file);
}
}
documents.Sort(delegate(Ofx.Document a, Ofx.Document b) { return a.startDate.CompareTo(b.startDate); });
// create merged statement object with properties of first file in files
Ofx.Document merged = new Ofx.Document();
merged.usePropertiesFrom(documents[0]);
merged.startDate = documents[0].startDate;
merged.endDate = documents[documents.Count - 1].endDate;
merged.closingBalanceDate = documents[documents.Count - 1].closingBalanceDate;
merged.closingBalance = documents[documents.Count - 1].closingBalance;
// add all the transactions from the first document to the merged document
foreach (SimpleOfx.BankTranListTypeSTMTTRN transaction in documents[0].transactions)
{
// add to transactions of merged statement
merged.transactions.Add(transaction);
}
System.Collections.Generic.List<string> warnings = new System.Collections.Generic.List<string>();
for (int index = 1; index < documents.Count; ++index)
{
int value = System.DateTime.Compare(documents[index].startDate, documents[index-1].endDate.AddDays(1));
if (value < 0)
{
// todo: address duplicate transactions
warnings.Add("overlapping date range between documents " + (documents[index - 1].m_fileName) + " and " + documents[index].m_fileName);
}
else if(value > 0)
{
warnings.Add("gap in date range between documents " + (documents[index - 1].m_fileName) + " and " + documents[index].m_fileName);
}
int laterClosingBalance = documents[index].closingBalance;
int earlierClosingBalance = documents[index - 1].closingBalance;
int transactionsInBetween = documents[index].sumOfTransactions();
if (earlierClosingBalance + transactionsInBetween != laterClosingBalance)
{
warnings.Add("Document " + documents[index].m_fileName + " has a closing balance of " + earlierClosingBalance + " which is inconsistent with its transactions (totalling " + transactionsInBetween + ") and the closing balance of " + laterClosingBalance + " in " + (documents[index - 1].m_fileName));
}
// add all the transactions to the merged document
foreach (SimpleOfx.BankTranListTypeSTMTTRN transaction in documents[index].transactions)
{
// add to transactions of merged statement
merged.transactions.Add(transaction);
}
}
if (warnings.Count > 0)
{
foreach (string warning in warnings)
{
System.Console.WriteLine(warning);
}
System.Console.ReadKey();
}
// write merged file
string outputFileName = string.Format("{0} - {1}.ofx", merged.startDate.ToString("yyyy-MM-dd"), merged.endDate.ToString("yyyy-MM-dd"));
merged.Save(outputDirectory + "/" + outputFileName);
}
示例11: DeleteOldFiles
private static void DeleteOldFiles(string filePattern, DirectoryInfo workingDirectory, FileInfo _file)
{
var cnt = workingDirectory.GetFiles(filePattern).Length;
var smaxLogFiles = System.Configuration.ConfigurationManager.AppSettings["maxlogfiles"];
var maxLogFiles = 5;
if (!int.TryParse(smaxLogFiles, out maxLogFiles))
maxLogFiles = 5;
if (cnt > maxLogFiles)
{
var sl = new System.Collections.Generic.List<FileInfo>();
foreach (var file in workingDirectory.GetFiles(filePattern))
sl.Add(file);
sl.Sort(new Comparison<FileInfo>(CompareFiles));
for (var ii = 0; ii < sl.Count; ii++)
{
if (ii < sl.Count - maxLogFiles)
{
try
{
sl[ii].Delete();
nHydrateLog.LogAlways(String.Format("Log File Deleted: {0} ", sl[ii].FullName));
}
catch (Exception ex)
{
nHydrateLog.LogLogFailure(ex.ToString());
}
}
}
}
foreach (var file in workingDirectory.GetFiles(filePattern))
{
try
{
var fileage = DateTime.Now.Subtract(file.LastWriteTime);
if (fileage.TotalDays > 7)
file.Delete();
}
catch (Exception ex)
{
nHydrateLog.LogLogFailure(ex.ToString());
}
}
}
示例12: ToCollectionSortByValue
/// <summary>
/// Trasforma l'HashTable corrente in una collection tipizzata <see cref="List<T>"/>
/// </summary>
/// <returns>Collection <see cref="List<T>"/> creata</returns>
public System.Collections.Generic.List<Tabella> ToCollectionSortByValue()
{
System.Collections.Generic.List<Tabella> collection = new System.Collections.Generic.List<Tabella>(this.Count);
foreach (DictionaryEntry de in this)
{
collection.Add((Tabella)de.Value);
}
collection.Sort(CompareByValue);
return collection;
}
示例13: Login
public bool Login()
{
var uri = new Uri("http://api.foursquare.com/v1/authexchange");
var sha1 = new HMACSHA1();
var key = Encoding.ASCII.GetBytes(ConsumerSecret + "&" + "");
if (key.Length > 64)
{
var coreSha1 = new SHA1CryptoServiceProvider();
key = coreSha1.ComputeHash(key);
}
sha1.Key = key;
var timeStamp = Common.GenerateTimeStamp();
var parameters = new System.Collections.Generic.List<string>
{
"oauth_consumer_key=" + HttpUtility.UrlEncode(ConsumerKey),
"oauth_nonce=" + HttpUtility.UrlEncode(Common.GetNonce(7)),
"oauth_timestamp=" + timeStamp,
"oauth_signature_method=HMAC-SHA1",
"oauth_version=1.0",
"fs_username=" + Username,
"fs_password=" + Password
};
parameters.Sort();
var parametersStr = string.Join("&", parameters.ToArray());
var baseStr = "GET" + "&" +
HttpUtility.UrlEncode(uri.ToString()) + "&" +
HttpUtility.UrlEncode(parametersStr);
var baseStringBytes = Encoding.UTF8.GetBytes(baseStr.Replace("%3d", "%3D").Replace("%3a", "%3A").Replace("%2f", "%2F"));
var baseStringHash = sha1.ComputeHash(baseStringBytes);
var base64StringHash = Convert.ToBase64String(baseStringHash);
var encBase64StringHash = HttpUtility.UrlEncode(base64StringHash);
parameters.Add("oauth_signature=" + encBase64StringHash);
parameters.Sort();
var requestUrl = uri + "?" + string.Join("&", parameters.ToArray());
var r = (HttpWebRequest)WebRequest.Create(requestUrl);
r.Method = "GET";
r.ContentType = "application/x-www-form-urlencoded";
try
{
var response = (HttpWebResponse)r.GetResponse();
//UserName = userName;
//Password = passWord;
var cevap = new StreamReader(response.GetResponseStream()).ReadToEnd();
var doc = new XmlDocument();
doc.LoadXml(cevap);
OAuthToken = doc.SelectSingleNode("//oauth_token").InnerText;
OAuthTokenSecret = doc.SelectSingleNode("//oauth_token_secret").InnerText;
response.Close();
//FS.OAuthToken = oauth_token;
//FS.OAuthTokenSecret = oauth_token_secret;
//message = cevap;
_HasToken = true;
return true;
}
catch (WebException ex)
{
//message = ex.Message;
return false;
}
}
示例14: PieceTogether
static bool PieceTogether(string src, string dest, ImageFormat format)
{
// Open the directory
DirectoryInfo dir = null;
try
{
dir = new DirectoryInfo(src);
}
catch (Exception ex)
{
Console.Error.WriteLine("There was a problem opening the directory '"+src+"': "+ex.Message);
return false;
}
// Go through each file
System.Collections.Generic.List<string> files = new System.Collections.Generic.List<string>();
foreach (FileInfo fi in dir.GetFiles("*"+GetExt(format)))
{
if (GetBitmap(fi.FullName, true) != null)
{
files.Add(fi.FullName);
}
}
if (files.Count == 0)
{
Console.Error.WriteLine("There were no acceptable files found in '"+src+"'");
return false;
}
if (files.Count != FRAMES)
{
Console.Error.WriteLine("Warning: Expected "+FRAMES+" frames but found "+files.Count+" frames in '"+src+"'");
}
files.Sort();
int size = ANIM_WIDTH * files.Count*ANIM_HEIGHT * 3; // bitmap data size
Bitmap b = new Bitmap(ANIM_WIDTH, files.Count*ANIM_HEIGHT, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(b);
for (int i = 0; i < files.Count; i++)
{
g.DrawImageUnscaled(GetBitmap(files[i], false), 0, i*ANIM_HEIGHT);
}
try
{
b.Save(dest, ImageFormat.Bmp);
}
catch (Exception ex)
{
Console.Error.WriteLine("There was a problem saving to '"+dest+"': "+ex.Message);
return false;
}
try
{
FileStream s = File.Open(dest, FileMode.Open, FileAccess.ReadWrite);
byte[] x = new byte[HEADER_SIZE];
s.Seek(0, SeekOrigin.Begin);
s.Read(x, 0, HEADER_SIZE);
//Adjust file size to be +1 of real (this is how the real activity.bmp is)
SetInt(size+HEADER_SIZE+1, x, 0x02);
//Add the BMP data size
SetInt(size, x, 0x22);
//Set the horiz and vert resolution to 0
SetInt(0, x, 0x26);
SetInt(0, x, 0x2A);
s.Seek(0, SeekOrigin.Begin);
s.Write(x, 0, HEADER_SIZE);
s.Close();
File.SetCreationTimeUtc(dest, DateTime.FromFileTime(creation_time));
File.SetLastWriteTimeUtc(dest, DateTime.FromFileTime(modification_time));
File.SetLastAccessTimeUtc(dest, DateTime.FromFileTime(accessed_time));
}
catch (Exception ex)
{
Console.Error.WriteLine("There was a problem adjusting the saved document '"+dest+"': "+ex.Message);
return false;
}
return true;
}
示例15: HandleAddItemFromMenu
string HandleAddItemFromMenu(object sender)
{
// Feb 2013 - Difference between this and old version will be that
// instead of storing the data in different ways for different types
// we keep it simple.
// We store only the GUIDs.
// The Display and Open Note (DoubleClick) functions, will have to handle the logic of figuring
// out what to do with the GUID -- i.e., showing a picture instead of text
// CORRECTION: I stuck with the original way of storing the data to not invalidate old data
// so simply we need to extract a CAPTION and GUID and we are off
System.Collections.Generic.List<NoteDataInterface> ListOfNotes = new System.Collections.Generic.List<NoteDataInterface>();
ListOfNotes.AddRange(Layout.GetAllNotes().ToArray (typeof(NoteDataInterface)) as NoteDataInterface[]);
ListOfNotes.Sort ();
LinkPickerForm linkpicker = new LinkPickerForm (LayoutDetails.Instance.MainFormIcon ,ListOfNotes);
DialogResult result = linkpicker.ShowDialog ();
if (result == DialogResult.OK) {
if (linkpicker.GetNote != null)
{
string sCaption = Constants.BLANK;
string sValue = Constants.BLANK;
string extraField = Constants.BLANK;
int type = 0;
linkpicker.GetNote.GetStoryboardData(out sCaption, out sValue, out type, out extraField);
StoryBoard.AddItem (sCaption, sValue, type, extraField);
// StoryBoard.InitializeGroupEmFromExternal();
}
// if (tempPanel != null) {
// // testing if a picture
// if (tempPanel.appearance.ShapeType == Appearance.shapetype.Picture) {
// string sFile = tempPanel.appearance.File;
// (sender as GroupEm.groupEms).AddItem (sText, sFile, 1);
// } else {
// // may 2010 -- tring to get the normal name not the fancy caption
//
// // add as link
// (sender as GroupEm.groupEms).AddItem (tempPanel.appearance.Caption, sValue, 0);
// }
//
// }
}
return "";
}