There is no possibility of distribution. And there are reasons for this.
- Properties are not an array in C # unless you use the params keyword
- Properties that use the param keyword must either:
- Share the same type
- Have a common shared type, such as double for numbers
- Be an object of type [] (since the object is the root type of everything)
However, by saying this, you can get similar functionality with different language features.
Answering your example:
WITH#
var arr = new []{ "1", "2"
The link you provide has the following example:
JavaScript Distribution
function sum(x, y, z) { return x + y + z; } const numbers = [1, 2, 3]; console.log(sum(...numbers));
Params In C # with the same type
public int Sum(params int[] values) { return values.Sum();
In C # with different numeric types using double
public int Sum(params double[] values) { return values.Sum();
Reflection In C # with various numeric types using object and reflection, this is probably the closest thing to what you are asking.
using System; using System.Reflection; namespace ReflectionExample { class Program { static void Main(string[] args) { var paramSet = new object[] { 1, 2.0, 3L }; var mi = typeof(Program).GetMethod("Sum", BindingFlags.Public | BindingFlags.Static); Console.WriteLine(mi.Invoke(null, paramSet)); } public static int Sum(int x, double y, long z) { return x + (int)y + (int)z; } } }
source share