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
Interface
May 9 2014 9:07 AM
In this program we are using
IComparable
interface but we didn't declare interface as such
public interface IComparable
{
int CompareTo(object o);
}
I assume that once we implemented the interface we didn't need declaration that is way declaration is not there in this program. This is true for any programs. I wish to know whether my understanding is correct. Problem is highlighted.
using System;
public class SchoolCompare
{
public static void Main()
{
School[] school = new School[8];
for (int x = 0; x < school.Length; ++x)
{
school[x] = new School();
Console.Write("Name of School #{0} ", x + 1);
school[x].SchoolName = Console.ReadLine();
Console.Write("Students Enrollment Nnuber: ");
school[x].StudentEnrolled = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
}
Array.Sort(school);
for (int x = 0; x < school.Length; ++x)
Console.WriteLine("School #{0} , Name: {1}, Enrollement Number: {2}",
x + 1, school[x].SchoolName, school[x].StudentEnrolled);
}
}
class School :
IComparable
{
private string sName;
private int enrolled;
public string SchoolName
{
get { return sName; }
set { sName = value; }
}
public int StudentEnrolled
{
get { return enrolled; }
set { enrolled = value; }
}
public int CompareTo(object o)
{
int returnVal;
School temp = (School)o;
if (this.enrolled > temp.enrolled)
returnVal = 1;
else
if (this.enrolled < temp.enrolled)
returnVal = -1;
else
returnVal = 0;
return returnVal;
}
}
Reply
Answers (
4
)
Adding a resuming feature to a download manager
reading power point in c#