public class bloodgroupdetails
{
int[] emp_code = new int[10];
string[] emp_name = new string[30];
int[] age = new int[5];
char[] address = new char[30];
char[] blood_grp = new char[10];
int[] salary = new int[10];
public int n, i;
public void getdata()
{
Console.WriteLine("\n how many employee details are going to be get:");
n = int.Parse(Console.ReadLine());
for (i = 0; i < n; i++)
{
Console.WriteLine("\nEnter the employee code:");
emp_code[i] = int.Parse(Console.ReadLine());
Console.WriteLine("\n enter the employee name:");
emp_name[i] = Console.ReadLine();
Console.WriteLine("\n enter the age:");
age[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\n enter the address:");
address[i] = Convert.ToChar(Console.ReadLine()); //// when i get input from user at runtime it show FORMATEEXCEPTION WAS UNHANDLED and i cannot go forward to get furture input.
Console.WriteLine("\n enter the blood group:");
blood_grp[i] = char.Parse(Console.ReadLine());
Console.WriteLine("\n enter the salary:");
salary[i] = int.Parse(Console.ReadLine());
}

VulpesPosted Nov 15, 2014, 1:55 PM
class Employee
{
public int Code {get; set;}
public string Name {get; set;}
public int Age {get; set;}
public string Address {get; set;}
public string BloodGroup {get; set; } // needs to be a string as char can't accomodate 'AB' blood group
public int Salary {get; set;}
}
public class BloodGroupDetails
{
public Employee[] Employees {get; set};
public void GetData()
{
Console.WriteLine("\n How many employee details are going to be entered:");
int n = int.Parse(Console.ReadLine());
Employees = new Employee[n];
for (int i = 0; i < n; i++)
{
Console.WriteLine("\nData for employee number {0}", i+1);
Employees[i] = new Employee();
Console.WriteLine("\nEnter the employee code:");
Employees[i].Code = int.Parse(Console.ReadLine());
Console.WriteLine("\n Enter the employee name:");
Employees[i].Name = Console.ReadLine();
Console.WriteLine("\n Enter the age:");
Employees[i].Age = int.Parse(Console.ReadLine());
Console.WriteLine("\n Enter the address:");
Employees[i].Address = Console.ReadLine();
Console.WriteLine("\n Enter the blood group:");
Employees[i].BloodGroup = Console.ReadLine();
Console.WriteLine("\n Enter the salary:");
Employees[i].Salary = int.Parse(Console.ReadLine());
}
}
}
Joginder BangerPosted Nov 15, 2014, 2:56 AM