ABC

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

//Program store data using list of structure

using System;
using System.Collections.Generic;

namespace studentdata
{
// store student name, Class, Roll No , Marks using structure
struct studentdata
{
public string sname;
public string clss;
public int rollno;
public int marks;
}
// List1 Demonstration of List
class list1
{
// Creating an List of Student data to store student Data and return value
using return statement
static List<studentdata> insert_data()
{
List<studentdata> s1 = new List<studentdata>();
studentdata s2;
s2.sname = "Ronit";
s2.clss = "BCA";
s2.rollno = 20;
s2.marks = 80;
s1.Add(s2);
s2.sname = "Lakhbir";
s2.clss = "MCA";
s2.rollno = 10;
s2.marks = 70;
s1.Add(s2);
s2.sname = "Amit";
s2.clss = "MCA";
s2.rollno = 120;
s2.marks = 78;
s1.Add(s2);
s2.sname = "Manbir";
s2.clss = "MCA";
s2.rollno = 90;
s2.marks = 40;
s1.Add(s2);
return s1;

}
// Defining function display_studentdata usin list parameter havi object s1
// Displaying the elements of List
static void display_studentdata(List<studentdata> s1)
{
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("\t\t\t Student Detail");

Console.WriteLine("----------------------------------------------------------------
---------------");
Console.WriteLine("Name\t\t\tClass\t\t Roll No\t\t Marks");
Console.WriteLine("----------------------------------------------------------------
---------------");
foreach (studentdata x1 in s1)
{
Console.WriteLine(x1.sname + "\t\t\t" + x1.clss + "\t\t\t" +
x1.rollno + "\t\t\t" + x1.marks);

Console.WriteLine("----------------------------------------------------------------
---------------");

}
static void Main(string[] args)
{
//store All data of student
List<studentdata> s1;
//store All data of student
s1 = insert_data();
// display the student Information
display_studentdata(s1);
Console.ReadKey();
}

You might also like