🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Burak HABER / C# / List ile Sınıf Kullanımı

1-) C# - List ile Sınıf Kullanımı

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 

namespace SınıfOlusturmaVeNesneKavrami

{

    public class Sinif

    {

        public int yas;

        public string cinsiyet;

        public int boy_cm;

    }

    public partial class Form3 : Form

    {

        public Form3()

        {

            InitializeComponent();

        }

 

        private void Form3_Load(object sender, EventArgs e)

        {

        }

        List<Sinif> Sinif1 = new List<Sinif>();//kopyalama

 

        private void button1_Click(object sender, EventArgs e)

        {

            /*Sinif1.Clear();

            Sinif ogrenci1 = new Sinif();

 

            ogrenci1.yas = 22;

            ogrenci1.cinsiyet = "Erkek";

            ogrenci1.boy_cm = 175;

 

            Console.WriteLine(ogrenci1.yas);

 

            ogrenci1.yas = 23;

            Console.WriteLine(ogrenci1.yas);

 

            Sinif ogrenci2 = new Sinif();

            ogrenci2.yas = 23;

            ogrenci2.cinsiyet = "kız";

            ogrenci2.boy_cm = 185;

 

            Sinif1.Add(ogrenci1);

            Sinif1.Add(ogrenci2);

            for (int i = 0; i < Sinif1.Count; i++)

            {

                Console.WriteLine(Sinif1[i].yas + " " + Sinif1[i].cinsiyet + " " + Sinif1[i].boy_cm);// yerini her zaman belirtmek zorundasın.

            }*/

 

 

 

            /***********************************************************************************/

 

 

 

            List<Sinif> Listem = new List<Sinif>();

 

 

            int yas1 = 20; int a = 0;

            for (int i = 0; i < 40; i++)

            {

                Sinif nesne = new Sinif();//kopyalama

                nesne.yas = yas1;

                nesne.cinsiyet = "erkek";

                nesne.boy_cm = 175;

                Listem.Add(nesne);

                yas1 = yas1 + 1;

                if (yas1 == 31)

                {

                    a = 40 - i;

                    break;

                }

 

            }

 

            for (int c = 0; c < a; c++)

            {

                Sinif nesne = new Sinif();//kopyalama

                nesne.yas = 21;

                nesne.cinsiyet = "erkek";

                nesne.boy_cm = 175;

                Listem.Add(nesne);

            }

 

            for (int i = 0; i < Listem.Count; i++)

            {

                Console.WriteLine(Listem[i].yas);

            }

            

            

 

 

 

        }

 

 

    }

}

 

 2021 Mart 11 Perşembe
 393