Click here to Skip to main content
15,880,972 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi to all.

i write a program with NEST Library of ElasicSearch in C#.
there is a method that it's argument is like this.



HighlighDescriptor<<parentdocument>> HighlighDescriptor<parentdocument>.onFields(param Action<<highlighfielddescriptor<><parentdocument>>>>[] fieldhighlighters)
how can i write it's lambada expression? my main problem is it's array in it's argument.

thakns.
Posted
Updated 23-Jun-15 1:48am
v4
Comments
deepankarbhatnagar 23-Jun-15 8:32am    
Not getting, please explain
Sergey Alexandrovich Kryukov 23-Jun-15 8:39am    
It sounds familiar… :-)
—SA

1 solution

it's only a param Array. You can add an array or you can csv actions, or you can have a single action.

It's just like String.Format(string format, param object[] args). params can be written as the following:

C#
String.Format(myFormatStr,args0,arg1, arg2) //csv 
String.Format(myFormatStr,args0)  // singular
String.Format(myFormatStr,args[]) // array
String.Format(myFormatStr)  //absent


EDIT: Added extra detail:

You can test this yourself and see what happens with a params parameter.

Here is a quick test class you can implement to see how it works:
C#
internal class Program
    {

        private static void Main()
        {
            //param arrays can be used in many ways:
            int[] factors = new[] {2, 3, 5}; 

            Console.WriteLine(  Product(9)          );    
                //9   1 paramaters will become an int[1]
            Console.WriteLine(  Product(2, 3)       );    
                //6   2 paramaters will become an int[2]
            Console.WriteLine(  Product(2, 3, 4)    );    
                //24  3 paramaters will become an int[3] 
            Console.WriteLine(  Product(factors)    );    
                //30  int[3] will remain int[3]
        }
        /// <summary>
        /// Multiplies all inputs and returns result
        /// </summary>
        /// <param name="factors">param input integers</param>
        /// <returns>product of inputs</returns>
        private static int Product(params int[] factors)
        {
            // factors are used as an int[]
            int result = 1;
            foreach (int factor in factors)
            {
                result *= factor;
            }
            return result;
        }
    }



So when you see that a parameter is an array but is has params in front of it then you don't have to pass an array.

Look - I don't know ElasicSearch which is why I am trying to explain param Action<<highlighfielddescriptor<><parentdocument>>>>[] fieldhighlighter instead.

This is what in might look like:
C#
//This is all guess work.  I do not know the format of the function items but you can use the parameter input in any of the following ways.
myHightlightDesc.onFields(f=>f.id);
myHightlightDesc.onFields(f=>f.id, f=>f.name);
myHightlightDesc.onFields(new []{f=>f.id, f=>f.name});
myHightlightDesc.onFields(f=>f.id, f=>f.name, f=>f.columm1+f.column2);


If you still need help the please tell me where you are stuck.

Good luck ^_^
 
Share this answer
 
v3
Comments
r.kh 23-Jun-15 8:13am    
can you explain more?
Andy Lanng 23-Jun-15 9:15am    
Updated solution ^_^
Philippe Mori 23-Jun-15 12:20pm    
Same could be said for the question...
Andy Lanng 23-Jun-15 12:30pm    
Ha ha. Well put. We should be able to rate comments
5* :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900