Apart from a little tidying up of the input code, you program looks pretty good so far.
Of course, you still need to do the following:
1. Change the phone number so it's a string - unless it's a very simple phone system you have there :)
2. Change the date of birth code so that there are 3 integers to store instead of one.
3. Sort the array into alphabetical order.
4. Once the array is sorted, you could use the Array.BinarySearch method to find a friend instead of looking through them individually. For large arrays, this method is much more efficient but it hardly matters for 8 folks.
5. A message needs to be displayed if the friend is not found. You might need to consider here whether to make the search case-insensitive or not.
This isn't a suitable example for using List<T> instead of an array because you're told in advance how many friends there are going to be. However, I've changed the code to demonstrate how you'd do it if you needed to.
The ToString() method overrides the virtual method of that name in System.Object from which all .NET types ultimately inherit. If you don't override it then, by default, ToString() returns the type name.
using System;
using System.Collections.Generic;
class FriendBirthday
{
static void Main()
{
List<Friend> friends = new List<Friend>();
string friendName;
int friendNumber;
int friendDateOfBirth;
Console.WriteLine("Please enter information about your 3 friends:\n\n ");
for (int index = 0; index < 3; index++)
{
Console.WriteLine("Details for friend {0}: ", index + 1);
Console.WriteLine("Enter friends name: ");
friendName = Console.ReadLine();
Console.WriteLine("Enter his phone number: ");
friendNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter his date of birth in the format of mm/dd/yy: ");
friendDateOfBirth = Convert.ToInt32(Console.ReadLine());
friends.Add(new Friend(friendName, friendNumber, friendDateOfBirth));
Console.WriteLine(); // space out the input a bit
}
Console.WriteLine("Enter friends name you looking for: ");
string userInput = Console.ReadLine();
for(int index = 0 ; index < friends.Count; index++)
{
if(userInput == friends[index].FriendName)
{
Console.WriteLine(friends[index].DateOfBirth);
break; // no need to go on
}
}
Console.ReadKey();
}
}
class Friend
{
public string FriendName { get; set; }
public int PhoneNumber { get; set; }
public int DateOfBirth { get; set; }
public Friend(string FriendName, int PhoneNumber, int DateOfBirth)
{
this.FriendName = FriendName;
this.PhoneNumber = PhoneNumber;
this.DateOfBirth = DateOfBirth;
}
public override string ToString()
{
return string.Format("Friends name: {0}, phone number: {1}, date of birth: {2}.", FriendName, PhoneNumber, DateOfBirth);
}
public int CompareTo(Friend otherFriend)
{
return this.FriendName.CompareTo(otherFriend.FriendName);
}
}