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
325.9k
ArrayList
Jun 28 2013 7:20 AM
Please correct this program to give following output.
/*
Abby Normal, 25
Jane Doe, 76
John Doe, 84
*/
using System;
using System.Collections;
namespace vi1
{
class Program
{
static void Main(string[] args)
{
ArrayList people = new ArrayList(); //this requires using System.Collections;
people.Add(new Person("John", "Doe", 84));
people.Add(new Person("Abby", "Normal", 25));
people.Add(new Person("Jane", "Doe", 76));
people.Sort();
for(int x=0; x<4; x++)
Console.WriteLine(people.ToString());
Console.ReadLine();
}
}
}
internal class Person : IComparable
{
private string fName;
private string lName;
private int age;
public Person(string fName, string lName, int age)
{
this.fName = fName;
this.lName = lName;
this.age = age;
}
new public string ToString()
{
return String.Format("{0}, {1}, {2}", fName, lName, age);
}
public int CompareTo(object o)
{
int returnVal;
Person temp = (Person)o;
if(this.age>temp.age)
returnVal=1;
else
if(this.age<temp.age)
returnVal=-1;
else
returnVal=0;
return returnVal;
}
}
Reply
Answers (
2
)
How to call a MACRO in C# ?
Need help with code please (New C# programmer)