Using two overloads of a function with params and a variable of the same type as params

时间:2016-02-12 21:45:15

标签: c# overloading params

I was writing a class with two diffrent constructor overloads:

    var rawItems = mongoItemsCollection
                             .Find(aggregateFilter)
                             .ToListAsync().Result;

After I wrote it, my code got me confused that how should I know that if the variable public class MyClass { public MyClass(params string[] Files) { } public MyClass(string Path, params string[] Files) { } } is given as argument or not. There is no error in program but I'm wondering for example if I run the following code, how to understand that Path is given or not?

Path

it can be either

MyClass x = new Myclass("a","b","c");

or just

Path = "a";
Files = string[]{"b","c"};

1 个答案:

答案 0 :(得分:0)

Try using named parameters:

MyFunction(parameter1: value1, parameter2: value2);