[닷넷강좌교육, C#객체/배열정렬, Array.Sort, IComparable을 이용하여 배열Sort하기]
using System;
class User : IComparable
{
public string Name
{
get;
set;
}
public int Age
{
get;
set;
}
public User(string name, int age)
{
Name = name;
Age = age;
}
// implement IComparable interface
public int CompareTo(object obj)
{
if (obj is User)
{
return this.Name.CompareTo((obj as User).Name); // compare user names
}
throw new ArgumentException("Object is not a User");
}
}
class SortTest
{
static void Main(string[] args)
{
User[] users = { new User("LEE", 23), // name, age
new User("KIM", 20),
new User("PARK", 25) };
Array.Sort(users);
foreach (User u in users) Console.WriteLine(u.Name + u.Age);
}
}
[결과]
KIM20
LEE23
PARK25
평일주간[100%환급과정]
(8/29)SQL기초에서 Schema Object까지
(8/29)Spring,MyBatis,Hibernate실무과정
(8/29)자바기초JDBC,Servlet/JSP까지
(8/29)PL/SQL,ORACLE HINT,TUNING
(9/15)C#4.0,WinForm,ADO.NET
(9/15)안드로이드개발자과정
(9/18)오라클자바채용확정교육
평일야간[개인80%환급]
(8/28)SQL기초에서실무까지
(8/28)자바JSP,jQuery,Spring,MyBatis
(8/29)Spring, MyBatis, Hibernate
(9/02)HTML5,CSS3,Ajax,jQuery마스터
(9/12)C#,Network,ADO.NET,ASP.NET
(9/16)안드로이드개발자과정
주말주간[개인80%환급]
(8/30)Spring, MyBatis, Hibernate
(8/30)SQL기초에서실무까지
(8/30)자바,네트워크,웹&스프링
(8/30)안드로이드개발자과정
(9/13)C#,ASP.NET마스터(9/13)웹퍼블리싱 마스터
(8/29)SQL기초에서 Schema Object까지
(8/29)Spring,MyBatis,Hibernate실무과정
(8/29)자바기초JDBC,Servlet/JSP까지
(8/29)PL/SQL,ORACLE HINT,TUNING
(9/15)C#4.0,WinForm,ADO.NET
(9/15)안드로이드개발자과정
(9/18)오라클자바채용확정교육
평일야간[개인80%환급]
(8/28)SQL기초에서실무까지
(8/28)자바JSP,jQuery,Spring,MyBatis
(8/29)Spring, MyBatis, Hibernate
(9/02)HTML5,CSS3,Ajax,jQuery마스터
(9/12)C#,Network,ADO.NET,ASP.NET
(9/16)안드로이드개발자과정
주말주간[개인80%환급]
(8/30)Spring, MyBatis, Hibernate
(8/30)SQL기초에서실무까지
(8/30)자바,네트워크,웹&스프링
(8/30)안드로이드개발자과정
(9/13)C#,ASP.NET마스터(9/13)웹퍼블리싱 마스터
댓글 없음:
댓글 쓰기