gemma browse

gemma browse

  • NA
  • 10
  • 61.3k

how to make the details save when adding them to the forum on c#

Dec 15 2010 6:23 AM
//B00519709 
//Gemma Browse

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using arun.CSharp.Namespaces;

//public class friend

class Program
{
static void Main(string[] args)
{
Friend[] friend = new Friend[4]; // using 4 different friends details

int x;
string firstname;
string surname;
string phonenumber;
int month;
int day;

for (x = 0; x < friend.Length; ++x)
{
GetData(out firstname, out surname, out phonenumber, out month, out day); // getting the data from the information needed
friend[x] = new Friend(firstname, surname, phonenumber, month, day);
}

Array.Sort(friend);
Console.WriteLine("Sorted List:");
for (x = 0; x < friend.Length; ++x)
Display(friend[x]);

Console.ReadLine();
}

public static void GetData(out string firstname, out string surname, out string phonenumber, out int month, out int day)
{
string inString;
Console.Write("Please enter your friend's firstname: "); // this is where the user is asked to enter the friends firstname
inString = Console.ReadLine();
firstname = Convert.ToString(inString);
Console.Write("Please enter your friend's surname: "); // this is where the user is asked to enter the friends surname
inString = Console.ReadLine();
surname = Convert.ToString(inString);
Console.Write("Please enter your friend's number: "); // this is where the user is asked to enter the friends number
inString = Console.ReadLine();
phonenumber = Convert.ToString(inString);
Console.Write("Please enter your friend's birth month: "); // this is where the user is asked to enter the friends birth month
inString = Console.ReadLine();
month = Convert.ToInt32(inString);
Console.Write("Please enter your friend's birth day: "); // this is were the user is asked to enter the friends birth day
inString = Console.ReadLine();
day = Convert.ToInt32(inString);
}

public static void Display(Friend fri)
{
Console.WriteLine(String.Format("{0},{1},{2},{3},{4}",fri.Firstname, fri.Surname, fri.Phone, fri.Month, fri.Day));
}
}

public class Friend : IComparable
{

public string Firstname { get; set; }
public string Surname { get; set; }
public string Phone { get; set; }
public int Month { get; set; }
public int Day { get; set; }

public Friend(string friendFirstName, string friendSurName, string friendNumber, int friendMonth, int friendDay)
{
Firstname = friendFirstName;
Surname = friendSurName;
Phone = friendNumber;
Month = friendMonth;
Day = friendDay;
}

public int CompareTo(object obj)
{
Friend temp = obj as Friend;
return this.Firstname.CompareTo(temp.Firstname);
}
}