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
324.9k
Non generic class
Oct 2 2012 9:42 AM
This program is producing run time error. How can non generic be implemented in this program. Problem is highlighted
using System;
namespace _6e13
{
class Program
{
static void Main(string[] args)
{
Friend[] friend = new Friend[3];
for (int x = 0; x < friend.Length; ++x)
{
friend[x] = new Friend();
Console.Write("Friend's Name ");
friend[x].name = Console.ReadLine();
Console.Write("Friend's Phone No ");
friend[x].pNo = int.Parse(Console.ReadLine());
Console.Write("Friend's DOB mm/dd/yyyy ");
friend[x].bDay = Console.ReadLine();
Console.WriteLine();
}
Console.WriteLine("\n{0, -15} {1, -18} {2, -20}", "Name", "Phone No", "DOB (mm/dd/yyyy)");
Console.WriteLine("{0, -15} {1, -18} {2, -20}", "====", "========", "================");
Console.WriteLine("\nBefore Sort");
for (int x = 0; x < friend.Length; ++x)
Console.WriteLine("{0, -15} {1, -18} {2, -20}", friend[x].name, friend[x].pNo, friend[x].bDay);
Array.Sort(friend);
Console.WriteLine("\nAfter Sort");
for (int x = 0; x < friend.Length; ++x)
Console.WriteLine("{0, -15} {1, -18} {2, -20}", friend[x].name, friend[x].pNo, friend[x].bDay);
Console.ReadKey();
}
}
}
class Friend
{
public string name { get; set; }
public int pNo { get; set; }
public string bDay { get; set; }
public int CompareTo(object o)
{
if (o is Friend)
{
Friend firstName = (Friend)o;
return string.Compare(this.name, firstName.name);
}
else
throw new ArgumentException("Object is not a Employee.");
}
}
Reply
Answers (
2
)
how to implement both mouse down and click events for button ?
Detecting Cycles