Showing posts with label protected. Show all posts
Showing posts with label protected. Show all posts

Friday, September 21, 2012

Erişim belirleyicisi örneği (C#)


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

namespace evler
{
    public class EV
    {
        private int katno;
        private int odasayisi;
        private string semt;


        public string Evgoster()
        {
           return string.Format("kat: {0} \noda: {1}\nsemt: {2}", katno,odasayisi,semt);
        }

        public int Katno
        {
            get { return katno; }
            set { katno = value; }
        }

        public int Odasayisi
        {    
            get
            {
                return this.odasayisi;
            }
            set
            {
                if (value < 0)
                {
                    value = Math.Abs(value);
                   
                }
                this.odasayisi = value;
            }
        }
        public string Semt
        {
            get { return semt; }
            set { semt = value; }
        }

    }
}


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

namespace siniflar
{
    class Program
    {
        static void Main(string[] args)
        {
            EV ev1 = new EV();

            ev1.Katno = 3;
            Console.WriteLine("oda sayisi: ");
            ev1.Odasayisi = Convert.ToInt32(Console.ReadLine());
            ev1.Semt = "besiktas";


            Console.WriteLine(ev1.Evgoster());

            Console.ReadLine();
        }
    }

}