Question: Write code to show how a method can accept a varying number of parameters.Answer: using System;namespace Console1 { class Class1 { static void Main(string[] args) { ParamsMethod(1,"example"); ParamsMethod(1,2,3,4); Console.ReadLine(); } static void ParamsMethod(params object[] list) { foreach (object o in list) { Console.WriteLine(o.ToString()); } } } } |
Is it helpful?
Yes
No
Most helpful rated by users:
- Name 10 C# keywords.
- What is public accessibility?
- .NET Stands for?
- What is private accessibility?
- What is protected accessibility?