🙂 İNSANLARIN EN HAYIRLISI INSANLARA FAYDALI OLANDIR 🙂

Burak HABER / C# / 54. Constructor (Yapıcı) Metotlar 2

1-) C# - 54. Constructor (Yapıcı) Metotlar  2

 

Kimlik.cs(add class)
using System;

 

namespace ornek

{

    class kimlik

    {

        string ad;

        string soyad;

        string memleket;

        int yas;

        char cinsiyet;

 

        public string AD

        {

            get { return ad; }

            set { ad = value.ToLower(); }

        }

 

        public string SOYAD

        {

            get { return soyad; }

            set { soyad = value.ToUpper(); }

        }

 

        public string MEMLEKET

        {

            get { return memleket; }

            set { memleket = value; }

        }

 

        public int YAS

        {

            get { return yas; }

            set { yas = Math.Abs(value); }

        }

        public char CINSIYET

        {

            get { return cinsiyet; }

            set { cinsiyet = value; }

        }

 

        public kimlik()//constructor (yapıcı) metotlar

        {

            ad = "";

            soyad = "";

            yas = 18;

            cinsiyet = 'k';

            memleket = "Ankara";

        }

 

 

 

    }

}

Program.cs(console)

using System;

 

namespace ornek

{

    class Program

    {

        static void Main(string[] args)

        {

            kimlik kml = new kimlik();

 

            kml.AD = "Burak";

            kml.SOYAD = "Haber";

            kml.MEMLEKET = "ANTALYA";

            Console.WriteLine(kml.AD);

            Console.WriteLine(kml.SOYAD);

            Console.WriteLine(kml.MEMLEKET);

            Console.WriteLine(kml.YAS);

            Console.WriteLine(kml.CINSIYET);

            Console.Read();

        }

    }

}


 2021 Mart 11 Perşembe
 518