Thursday, 21 November 2013

C# Simple Structure program....

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleAppstruct
{
    public class abc
    {
        struct stud
        {
            public int emp;
            public string name;
            public void display()
            {
                Console.WriteLine("Emp_id is:" + emp);
                Console.WriteLine("Name is:" + name);
            }
        }

        public static void Main(string[] args)
        {
            stud[] obj = new stud[5];
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("Enter employee id " + (i + 1) + " emp_id");
                obj[i].emp = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter employee name" + (i + 1) + "name");
                obj[i].name = Console.ReadLine();
            }
            for (int j = 0; j < 5; j++)
            {
                obj[j].display();
            }
            Console.ReadKey();
        }
    }
}

Output:

No comments:

Post a Comment