Monday 17 September 2018

Types of LIST collection

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

namespace TypesOfList
{
    class Program
    {
        static void Main(string[] args)
        {
            var students = school.getAllStudents();

            foreach (var student in students)
            {
                Console.WriteLine("The Id is " + student.Sid + " and the Name " + student.Sname + " is and he is pass" + student.Pass + "\n");
            }
            Console.ReadLine();
        }

    }
    public class Student
    {
        public int Sid { get; set; }
        public String Sname { get; set; }
        public bool Pass { get; set; }
    }

    public class school
    {
        public static List getAllStudents()
        {

            //Type 1 to rerun the List values
            //return new List()
            //{

            //        new Student{Sid=1,Sname= 1 +"-A",Pass=true},
            //        new Student{Sid=2,Sname= 1 +"-B",Pass=false},

            //};

            //Type 2 to retuen the foe loop list
            //List student = new List();
            //for (int i = 0; i < 100; i++)
            //{
            //    student.Add(new Student { Sid = i, Sname = i + " - AbC -" + i + 1, Pass = true });
            //}
            //return student;

            //Type 3 Creating the object and insering them to the parent List class
            Student s1 = new Student()
            {
                Sid = 1,
                Sname = "ABC",
                Pass = true
            };
            Student s2 = new Student()
            {
                Sid =21,
                Sname = "ADs",
                Pass = true
            };
            List student = new List();
            student.Add(s1);
            student.Add(s2);
            return student;
             
        }
    }
}

No comments:

Post a Comment