Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Sort example
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { List<Test> tList = new List<Test> () { new Test("A", 1, 2), new Test("B", 5, 1), new Test("C", 0, 4), new Test("D", 5, 0), new Test("E", 0, 4) }; //Console.WriteLine(string.Join(",", tList.ConvertAll<string>(t => (t == null).ToString()))); /*tList.Sort((a, b) => { if ( a.x > b.x) { return 1; } else if (b.x > a.x) { return -1; } else { if ( a.y >= b.y) { return 1; } else { return -1; } } });*/ tList.Sort(); //Your code goes here Console.WriteLine(string.Join(",", tList.ConvertAll<string>(t => t.name))); } } public class Test : IComparable { public string name; public int x; public int y; public Test(string name, int x, int y) { this.name = name; this.x = x; this.y = y; } public int CompareTo(object obj) { if (obj == null) return 1; Test otherTest = obj as Test; if (otherTest != null) { int compare = x.CompareTo(otherTest.x); if ( compare == 0 ) { compare = y.CompareTo(otherTest.y); } return compare; } else { throw new ArgumentException("Object is not a Test"); } } } }
Show compiler warnings
[
+
]
Show input
Compilation time: 0,28 sec, absolute running time: 0,14 sec, cpu time: 0,16 sec, average memory usage: 14 Mb, average nr of threads: 3, absolute service time: 0,43 sec
edit mode
|
history
|
discussion
C,E,A,D,B