Params Deyimini Kullanmak1,

Bazen sayısı belli olmayan(run time da belli olacak) parametreleri bir yonteme göndermek isteyebilrisiniz.

 

class Program
    {
        static void Main(string[] args)
        {
            dene d = new dene();
            Console.WriteLine(d.Topla(3, 4, 4));
            Console.WriteLine(d.Topla(3,4,5,6,7,4));        }
    }
    class dene
    {
        public int Topla(params int[] sayilar)
        {
            int topla=0;
            foreach (int item in sayilar)
	        {
                topla += item;
	        }
            return topla;
        }
    }

Ayrıca params kullanmadan bazı teknikler kullanabilirsiniz. İş parçacıkları oluşturmak, kodun okunurluğu ve esnekliği açısından uygun olacaktır.

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            dene d = new dene("ali");
            d.yaz();
            Console.WriteLine(d.Topla(3, 4, 4));
            Console.WriteLine(d.Topla(3,4,5,6,7,4));        }
    }
    class dene
    {
        dene()
        {

        }
        string dd;
        public dene(string deneme)
        {
            dd=deneme;
        }
        public void yaz()
        {
            Console.WriteLine("yaz" +dd);
        }
        public int Topla(params int[] sayilar)
        {
            int topla=0;
            foreach (int item in sayilar)
	        {
                topla += item;
	        }
            return topla;
        }
    }
    class Matematik
    {
        public Matematik()
        {

        }
        static int pi = 4;
        public static double Toplam(double x, double y)
        {
            return x + y;
        }


        //Params deyimini kullanmadan bazı yontemlerimizi genişletebilirsiniz.
        public static double Toplam(double x, double y, double z)
        {
            return (Toplam(x,y))+z;
        }
        public double Toplamlar(int ustSinir, double x, double y)
        {
            double sonuc = 0;
            for (int i = 0; i < ustSinir; i++)
                sonuc += Toplam(x, y);
            return sonuc;
        }
    }
}
The file '/Custom/Widgets/Calendar/widget.cshtml' does not exist.The file '/Custom/Widgets/Category list/widget.cshtml' does not exist.The file '/Custom/Widgets/Tag cloud/widget.cshtml' does not exist.The file '/Custom/Widgets/Page List/widget.cshtml' does not exist.The file '/Custom/Widgets/Month List/widget.cshtml' does not exist.