Swift part2
■ このスレッドは過去ログ倉庫に格納されています
0174デフォルトの名無しさん
2014/06/20(金) 20:44:08.81ID:kEPVLal9//------------ C# (空白は全角を使っている)
class Program
{
static void Main(string[] args)
{
var list = new List<Tuple<int, string>>();
list.Add(Tuple.Create(31, "Jan"));
list.Add(Tuple.Create(28, "Feb"));
list.Add(Tuple.Create(31, "Mar"));
list.Add(Tuple.Create(30, "Apr"));
list.Add(Tuple.Create(31, "May"));
list.Sort((Tuple<int, string> t1, Tuple<int, string> t2) => (t2.Item1 - t1.Item1));
foreach (var t in list)
{
Console.WriteLine("{0} {1}", t.Item1, t.Item2);
}
}
}
//--------- Swift
let lists:(days: Int , month: String)[] = [ (31, "Jan") , (28, "Feb") , (31, "Mar") , (30, "Apr") , (31, "May") ]
sort ( lists , { $0.days < $1.days } )
println( lists )
/* ---------- このSwiftの sort 部分は、次のようにも書ける
sort ( lists , { ( t1, t2 ) -> Bool in t1.days < t2.days } ) // 或は
sort ( lists , { t1, t2 in t1.days < t2.days } )
*/
■ このスレッドは過去ログ倉庫に格納されています