MODEL CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication15.Model
{
class student
{
int id;
string name;
public static string batchcode="1708C1";
public student(int id,string name)
{
this.id = id;
this.name = name;
}
public void displayrecord()
{
Console.ForegroundColor = System.ConsoleColor.Red;
Console.WriteLine("----------------------------------");
Console.ForegroundColor = System.ConsoleColor.Green;
Console.WriteLine("ID= " + id);
Console.WriteLine("Name = "+name);
Console.ForegroundColor = System.ConsoleColor.Cyan;
Console.WriteLine("Batch Code: "+batchcode);
Console.ForegroundColor = System.ConsoleColor.Red;
Console.WriteLine("----------------------------------");
}
}
}
MAIN CLASS CODE:
class Program
{
static void Main(string[] args)
{
student[] arr = new student[4];
for (int i = 0; i < arr.Length; i++)
{
Console.WriteLine("ENTER THE NAME OF STUDENT: ");
string n = Console.ReadLine();
arr[i] = new student((i + 234), n);
}
foreach (student item in arr)
{
item.displayrecord();
}
Console.ReadLine();
}
}
No comments:
Post a Comment