TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maha
NA
0
326k
Array.Sort()
Aug 29 2012 12:09 PM
In this program
Array
.Sort(x,
new
data.sortDes
());
is used. Please give me relevant website address to get more information about this. Problem is highlighted.
using System;
using System.Collections;
namespace ConsoleApplication5
{
class data : IComparable
{
string name;
int age;
public data()
{
}
public data(string name, int age)
{
this.name = name;
this.age = age;
}
public string _name
{
get{return name;}
}
public int _age
{
get{return age;}
}
public int CompareTo(object obj)
{
data m = (data)obj;
if (m._age < this._age)
return 1;
else if (m._age > this._age)
return -1;
else
return 0;
}
public class sortDes : IComparer
{
int IComparer.Compare(object x, object y)
{
data m = (data)x;
data n = (data)y;
if (m._age < n._age)
return 1;
else
if (m._age > n._age)
return -1;
else
return 0;
}
}
}
class Program
{
static void Main(string[] args)
{
data[] x = new data[4];
x[0] = new data("Ali", 10);
x[1] = new data("Mohammed", 24);
x[2] = new data("Wael", 3);
x[3] = new data("Slah", 34);
// Array.Sort(x) //for will sort it Ascending
Array.Sort(x, new data.sortDes());
foreach (data d in x)
Console.WriteLine(d._name + " " + d._age.ToString());
Console.ReadKey();
}
}
}
/*
Slah 34
Mohammed 24
Ali 10
Wael 3
*/
Reply
Answers (
2
)
Architechture question (Code design)
about running a scheduled tasks in our machine daily and particular time