Showing posts with label erişim belireyicisi. Show all posts
Showing posts with label erişim belireyicisi. Show all posts

Friday, September 21, 2012

Erişim Belirleyici yardımıyla dosyaya yazma (C#)

Erişim Belirleyici yardımıyla dosyaya yazma


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

namespace evler
{
    public class Ev
    {
        private int odasayisi;
        private int katno;
        private double alan;
        private string semt;
     
     
        public int Odasayisi
       {
           get
           {
               return odasayisi;
           }

           set
           {
               if (value < 0)
               {
                   FileInfo fi = new FileInfo("c:/Netgame/loglar.txt");
                   FileStream fs;
                      if (fi.Exists == true)
                       {
                          fs = new FileStream("c:/Netgame/loglar.txt", FileMode.Append);
                       }

                      else
                          fs = new FileStream("c:/Netgame/loglar.txt", FileMode.Create);

                      StreamWriter yazici = new StreamWriter(fs);
                      yazici.Write("hatalı deger girildi("+DateTime.Now+")");
                      yazici.Flush();
                      yazici.Close();
                      fs.Close();

               }
               value = Math.Abs(value);
               odasayisi = value;
           }
       }


         public int Katno
        {
            get
            {
                return katno;
            }

            set
            {
                this.katno = value;
            }
        }

         public double Alan
         {
             get
             {
                 return this.alan;
             }

             set
             {
                this.alan = value;
             }
         }

         public string Semt
         {
             get
             {
                 return semt;
             }

             set
             {
                 semt = value;
             }
        }

         public string EvGoster()
        {
            return string.Format(" Odasayisi: {0} \n Katno: {1} \n Alan: {2} \n Semt: {3}", odasayisi, katno, alan, semt);
        }
   }
}



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

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

            ev1.Odasayisi = -5;
            ev1.Katno = 2;
            ev1.Alan = 120;
            ev1.Semt = "Besiktas";
         
            Console.WriteLine(ev1.EvGoster());
            Console.ReadLine();
        }
    }
}

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();
        }
    }

}