Params C#
unknown
csharp
2 years ago
967 B
19
Indexable
// Online C# Editor for free
// Write, Edit and Run your C# code using C# Online Compiler
using System;
public class HelloWorld
{
public static void Main(string[] args)
{
int a = 10;
int b = 10;
int c = 10;
void Print(string title, string message = "Hello World")
{
Console.WriteLine(title);
Console.WriteLine(message);
}
Print("Title", "Alemkhan");
// 10, 10, 10, a, b, c
// 10
// new int[] {10, 10, 10}
//
int Sum (string title, string message = "", params int[] numbers)
{
int result = 0;
Console.WriteLine(title);
Console.WriteLine(message);
for(int i = 0; i < numbers.Length; i++)
{
result += numbers[i];
}
return result;
}
int[] array = new int[] {10, 10, 10};
Console.WriteLine(Sum(numbers: array, title: "Title", message: "Message"));
}
}Editor is loading...
Leave a Comment