Metotlarla ilgili Örnek

Metotlarla ilgili Örnek

 static void Main(string[] args)
        {
            metot nesne = new metot();
            Console.WriteLine("Sayıyı giriniz....");
            int sayi = Convert.ToInt32(Console.ReadLine());
           int bilgi= nesne.pozneg(sayi);
           if (bilgi == 1)
               Console.WriteLine("{0} sayısı pozitiftir...", sayi);
           else
               Console.WriteLine("{0} sayısı negatiftir..", sayi);

           nesne.tekcift(sayi);
           int sayinin_karesi = nesne.karesi(sayi);
           Console.WriteLine("{0} sayısının karesi={1}",sayi,sayinin_karesi);

           Console.ReadLine();
        }

 class metot
    {
        public int pozneg(int x)
        {
            if (x < 0)
                return 0;
            else
                return 1;        
        }

        public void tekcift(int sayi)
        {
            if (sayi % 2 == 0)
                Console.WriteLine("Sayı çifttir...");
            else
                Console.WriteLine("Sayı Tektir...");
        }

        public int karesi(int a)
        {
            int sonuc = a * a;
            return sonuc;
        
        }
    }

admin