struct record
{
public int Age;
public string Name;
};
static void Main(string[] args)
{
record[] data1 = new record[5];
Console.Write("Employee............");
Console.WriteLine();
for (int n = 1; n < data1.Length; n++)
{
Console.Write("Enter name[" + n + "] :");
data1[n].Name = Console.ReadLine();
Console.Write("Enter Age[" + n + "] :");
data1[n].Age = int.Parse(Console.ReadLine());
}
Console.WriteLine();
Console.Write("Output...\n");
Console.WriteLine();
for (int n = 1; n < data1.Length; n++)
{
if (data1[n] < data1[n + 1])
{
n = data1[n].Age;
data1[n] = data1[n + 1];
data1[n + 1] = n;
}
Console.Write(n + 0 + "." + data1[n].Name + ":" + data1[n].Age);
Console.WriteLine();
}
Console.Read();
Code
Error 1 Operator '<' cannot be applied to operands of type 'ConsoleApplication7.Program.record' and 'ConsoleApplication7.Program.record'
2 Cannot implicitly convert type 'int' to 'ConsoleApplication7.Program.record'
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
class record
{
public int No { get; set; }
public string Name { get; set; }
public int Age {get; set;}
};
static void Main(string[] args)
{
var data1 = new List<record>();
int iMax = 5;
Console.Write("Employee............");
Console.WriteLine();
for (int n = 1; n < iMax; n++)
{
Console.Write("Enter name[" + n + "] :");
String sName = Console.ReadLine();
Console.Write("Enter Age[" + n + "] :");
int iAge = Convert.ToInt32(Console.ReadLine());
// Add Item
data1.Add(new record { No=n, Name = sName, Age = iAge });
}
Console.WriteLine();
Console.Write("Output...\n");
Console.WriteLine();
// Sort
var data2 = data1.OrderBy(o => o.Age);
// Loop Display
foreach (var item in data2)
{
Console.WriteLine(String.Format("No = {0}, Name = {1}, Age = {2}", item.No, item.Name, item.Age));
}
Console.Read();
}
}
}