中の技術日誌ブログ

C#とC++/CLIと
VBと.NETとWindowsで戯れる
 

目次

Blog 利用状況

ニュース

自己紹介

東京でソフトウェアエンジニアをやっています。
お仕事大募集中です。
記事執筆や、講師依頼とかでも何でもどうぞ(*^_^*)
似顔絵 MSMVPロゴ
MSMVP Visual C# Since 2004/04-2013/03

記事カテゴリ

書庫

日記カテゴリ

00-整理

01-MSMVP

Listを使うソート

string [] ss = xxxx;
List<string> NewList = new List<string>(ss);
NewList.Sort(new Comparison<string>(
 delegate(string x, string y)
 {
  return string.Compare(x, y);
 }));

これが1つのパターンになるかな。

 

投稿日時 : 2006年2月10日 1:02

コメントを追加

# re: List<T>を使うソート 2006/02/10 8:59 データ

string [] ss = xxxx;
List<string> NewList = new List<string>(ss);
NewList.Sort(new Comparison<string>(string.Compare));

の方が...。

# re: List<T>を使うソート 2006/02/10 10:35 青柳 臣一

string は IComparable を実装してるから
  NewList.Sort();
だけで、、、とかってことじゃなくてパターンとしての一例なんですよね?

C# 2.0 からは delegate がコンパイル時に推測可能なときは明示しなくてもよくなったので
  NewList.Sort(delegate(string x, string y) { ... });
で大丈夫です。
もちろん、
  NewList.Sort(string.Compare);
とも書けます。

# re: List<T>を使うソート 2006/02/10 10:43 中博俊orz

ああ、new Comparison もいらんかったですね。orz
ほんとのソース

FileInfo[] NewFiles = this.NewDirInfo.GetFiles();
List<FileInfo> NewFileList = new List<FileInfo>(NewFiles);
NewFileList.Sort(
delegate(FileInfo x, FileInfo y)
{
return string.Compare(x.Name, y.Name);
});

# You saved me a lot of hsalse just now. 2012/10/17 14:56 Hiroyuki

You saved me a lot of hsalse just now.

# Oakley Sunglasses Cheap 2013/03/13 19:18 http://oakleyfrogskins2.cabanova.com/

Would you like a cup of tea? Columbus discovered America in l492.Her family are all music lovers.The play may begin at any moment.Here's a gift for you.The number 13 bus will take you to the hospital.The whole world knows that.How did the game turn out?Japan is to the east of China.I'm doing some washing and John is cooking dinner

タイトル
名前
URL
コメント