如何写这个函数的Lambada表达式? [英] How Can I Write Lambada Expression Of This Function?

查看:98
本文介绍了如何写这个函数的Lambada表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



i在C#中用EESTicSearch的NEST库编写一个程序。

有一个方法,它的论点是像这样。







HighlighDescriptor<< parentdocument>> HighlighDescriptor< parentdocument> .onFields(param Action<< highlighfielddescriptor<>< parentdocument>>>> [] fieldhighlighters)

我怎么能写出它的lambada表达式?我的主要问题是它的参数中的数组。



thakns。

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.

推荐答案

它只是一个参数数组。你可以添加一个数组,也可以csv动作,或者你可以有一个动作。



它就像 String.Format(字符串格式) ,param object [] args)。 params可以写成如下:



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:

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





编辑:增加了额外的细节:



您可以自己测试一下,看看params参数会发生什么。



这是一个快速测试类,你可以实现它看看它是如何工作的:



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:

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;
        }
    }







所以当你看到一个参数是一个数组但是在它前面有 params 然后你不必传递一个数组。



看看 - 我不知道ElasicSearch这就是为什么我要解释 param Action<< highlighfielddescriptor<>< parentdocument>>>> [] fieldhighlighter 相反。



这是可能的样子:




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:

//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 ^_^


这篇关于如何写这个函数的Lambada表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆