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
328.2k
Using Automatic properties & Generics
Dec 19 2011 7:07 PM
This is modification of an original program having get and set method. Modified program Using Automatic properties and Generics. Please anyone help me to correct the errors. Comment out block shows how must be the output look like.
using System;
namespace ConsoleApplication1
{
class StudetCompare
{
static void Main(string[] args)
{
int x;
Student[] student = new Student[3];
for (x = 0; x < student.Length; ++x)
{
Console.Write("Student #{0} ID = ", x + 1);
int id = Convert.ToInt32(Console.ReadLine());
student[x].ID = id;
Console.Write("Name: ");
string name = Console.ReadLine();
student[x].Name = name;
Console.Write("GPA = ");
double gpa = Convert.ToDouble(Console.ReadLine());
student[x].GPA = gpa;
Console.WriteLine();
}
Console.WriteLine("Student #{0} ID = {1}, Name: {2}, GPA = {3}", student[x].ID, student[x].Name, student[x].GPA);
Console.ReadKey();
}
}
class Student : IComparable<Student>
{
public int ID { get; set; }
public string Name { get; set; }
public double GPA { get; set; }
public int CompareTo(Student student)
{
int returnVal;
if (this.ID > student.ID)
returnVal = 1;
if (this.ID < student.ID)
returnVal = -1;
else
returnVal = 0;
return returnVal;
}
}
}
/*
Student #1 ID = 200
Name: Maha
GPA = 2.9
Student #2 ID = 300
Name: Cad
GPA = 3.5
Student #3 ID = 100
Name: Tef
GPA = 4.6
Student #1 ID = 100, Name: Tef, GPA = 4.6
Student #2 ID = 200, Name: Maha, GPA = 2.9
Student #3 ID = 300, Name: Cad, GPA = 3.5
*/
Reply
Answers (
3
)
Rewrite the .NET code
SNMP trap implementation