V C#, params je ključna beseda, ki se uporablja za določanje parametra, ki sprejme spremenljivo število argumentov. Uporabno je, ko ne poznamo števila predhodnih argumentov. Dovoljena je samo ena ključna beseda params in noben dodatni parameter ni dovoljen za ključno besedo params v deklaraciji funkcije.
1. primer parametrov C#
using System; namespace AccessSpecifiers { class Program { // User defined function public void Show(params int[] val) // Params Paramater { for (int i=0; i<val.length; i++) { console.writeline(val[i]); } main function, execution entry point of the program static void main(string[] args) program(); creating object program.show(2,4,6,8,10,12,14); passing arguments variable length < pre> <p> <strong>Output:</strong> </p> <pre> 2 4 6 8 10 12 14 </pre> <h3>C# Params Example 2</h3> <p>In this example, we are using object type params that allow entering any number of inputs of any type.</p> <pre> using System; namespace AccessSpecifiers { class Program { // User defined function public void Show(params object[] items) // Params Paramater { for (int i = 0; i <items.length; i++) { console.writeline(items[i]); } main function, execution entry point of the program static void main(string[] args) program(); creating object program.show('ramakrishnan ayyer','ramesh',101, 20.50,'peter', 'a'); passing arguments variable length < pre> <p> <strong>Output:</strong> </p> <pre> Ramakrishnan Ayyer Ramesh 101 20.5 Peter A </pre> <br></items.length;></pre></val.length;>
2. primer parametrov C#
V tem primeru uporabljamo parametre vrste objekta, ki omogočajo vnos poljubnega števila vnosov katere koli vrste.
using System; namespace AccessSpecifiers { class Program { // User defined function public void Show(params object[] items) // Params Paramater { for (int i = 0; i <items.length; i++) { console.writeline(items[i]); } main function, execution entry point of the program static void main(string[] args) program(); creating object program.show(\'ramakrishnan ayyer\',\'ramesh\',101, 20.50,\'peter\', \'a\'); passing arguments variable length < pre> <p> <strong>Output:</strong> </p> <pre> Ramakrishnan Ayyer Ramesh 101 20.5 Peter A </pre> <br></items.length;>