Metot Kullanımı(Deger döndürmeyen)

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

namespace metodlar
{
    class Program
    {
        static void Main(string[] args)
        {
            Selamlama();
            Selamlama();
            Selamlama();
            Console.ReadLine();
        }
        static void Selamlama()
        {
            Console.WriteLine("Merhaba");
           
        }
    }
}




Parametreli Metot Kullanımı

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

namespace metodlar
{
    class Program
    {
        static void Main(string[] args)
        {
            toplamaMetodu(8, 10);  //8 ve 10 degerini olusturdugumu toplamaMetoduna gönderiyoruz.
            
        }
        static void toplamaMetodu(int a,int b)
        {
            Console.WriteLine("Toplamın sonucu:"+(a+b));
            Console.ReadLine();

        }
    }
}


Return Kullanımı (Geriye deger döndüren)

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

namespace @return
{
    class Program
    {
        static void Main(string[] args)
        {
   int   sonucDegeri=toplamayap(5,9);

            if (sonucDegeri > 15)
            {
                Console.WriteLine("Sayi 15den buyuk");
                
            }
            else
            {
                Console.WriteLine("Sayı 15 den ufak");
            }
            Console.ReadLine();
            
          
        }
        static int toplamayap(int sayi1,int sayi2)
        {            
            int sonuc = sayi1 + sayi2;
            Console.WriteLine("sonuc:"+sonuc);
            return sonuc;
        }
    }
}

Bu Paylaşıma Yorum Yaz

Daha yeni Daha eski