Posted by : Anwar Hossain
Category : asp.net c # basic tutorial

Store C sharp reference type in a List C#

Dear viewers in this tutorial I will show how to store reference type data into c sharp List. We know a list of item can be accessed by indexed and has many functions and properties. In this example I have created a class named Employee and created necessary properties. Now I have used List Add function to add Employee information. After adding Employee information I have also shown how to use properties and functions of List.

Store C Sharp reference type in a List C#

Store C # reference type in a List C#

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ListReference

{

 

    class Program

    {

        static void Main(string[] args)

        {

               

            List<Employee> EmployeeList = new List<Employee>();

            EmployeeList.Add(new Employee("Iqbal Hossain", "08159965875", "Noakhali", 25000));

            EmployeeList.Add(new Employee("Zabed Hossain", "08159955875", "Dhaka", 50000));

            EmployeeList.Add(new Employee("Samsul Hossain", "08159565875", "Chittagong",22000));

            EmployeeList.Add(new Employee("Rahim Akhter", "08159965845", "Rajshai",16000));

            EmployeeList.Add(new Employee("Roman Hossain", "08159965812", "Rajshai",22000));

            EmployeeList.Add(new Employee("Jamal Hossain", "08159965865", "Chandpur",23000));

            EmployeeList.Add(new Employee("Prince  Hossain", "0815976875", "Noakhali",50000));      

            Console.WriteLine("Employee List ");

 

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

            foreach (var employee in EmployeeList)

            {

                Console.WriteLine("Employee List : {0}, {1}, {2}, {3}", employee.EmployeeName, employee.EmployeePhone, employee.EmployeeAddress,employee.EmployeeSalery);

            }

 

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

            Console.WriteLine("Count Eemployee  ");

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

            Console.WriteLine("\n There are: {0}, {1}", EmployeeList.Count,"Employees available ");

 

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

 

            Console.ReadLine();

 

        }

    }

    public class  Employee

    {

        private string employeeName;

        private string employeePhone;

        private string employeeAddress;

        private double employeeSalery;

 

 

        public Employee(string employeeName, string employeePhone, string employeeAddress, double employeeSalery)

        {

            this.employeeName = employeeName;

            this.employeePhone = employeePhone;

            this.employeeAddress = employeeAddress;

            this.employeeSalery = employeeSalery;

           

        }

 

        public string EmployeeName

        {

            get { return employeeName; }

            set { employeeName = value; }

        }

 

        public string EmployeePhone

        {

            get { return employeePhone; }

            set { employeePhone = value; }

        }

        public string EmployeeAddress

        {

            get { return employeeAddress; }

            set { employeeAddress = value; }

        }

        public double EmployeeSalery

        {

            get { return employeeSalery; }

            set { employeeSalery = value; }

        }

       

    }

   

}

Out Put

store-reference-type-list-c-sharp



Realted Article Headline

How to find odd number in c #
How to generate random number in c #
Nested For Loop Example in C Sharp
Store C sharp reference type in a List C#
Find number of items in a List C#
Concept about C # List
Custom Time formatting example C #
Custom Date formatting example C #
String Format Example using ASP.Net C#
Simple enum example in C Sharp
Nested switch-case statement example in C #
Combined switch...case statement example in C #
C Sharp switch case statement Example
C# SUM ArrayList Element Example
C# String Class Methods Example
C Sharp String Class Properties and Methods
C Sharp String Class Example
How to join two ArrayList collections in C#.
How to Use C Sharp Math Class
C Sharp ArrayList Property and Method
C Sharp ArrayList Example
C Sharp Arrays Example
C Sharp Logical operator Example
C Sharp Relational operators
C Sharp Arithmetic operators Example
C Sharp Common Assignment Operator
Simple for loop example in c sharp

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection