【问题标题】:how can i call & fill function 2d parameter inline?我如何调用和填充函数 2d 参数内联?
【发布时间】:2014-01-10 00:13:04
【问题描述】:

我有以下具有二维数组的函数

public string StoredProcedure(Func<string[,]> StoredProcedureParameterFunc)
{
   string[,] StoredProcedureParameter = StoredProcedureParameterFunc();
   return StoredProcedureParameter.Length.ToString();
}

我这样称呼它

public string test_Selecting()
{
   string x =StoredProcedure(delegate {string[,] a = new string[,] 
   {{"ant","aunt"},{"Sam","Samantha"},{"clozapine","quetiapine"}}; return a;});
   return x;
}

我需要更简单的方法来调用和填充二维列表或二维数组内联

【问题讨论】:

    标签: c# function delegates inline


    【解决方案1】:

    您可以使用Func委托如下:

    public string StoredProcedure(Func<string[,]> StoredProcedureParameterFunc)
    {
        string[,] StoredProcedureParameter = StoredProcedureParameterFunc();
        return StoredProcedureParameter.Length.ToString();
    }
    
    ...
    
    StoredProcedure(() => new string[,] { { "ant", "aunt" }, { "Sam", "Samantha" }, { "clozapine", "quetiapine" } });
    

    【讨论】:

      猜你喜欢
      • 2019-06-19
      • 2020-11-05
      • 2012-02-23
      • 1970-01-01
      • 2021-03-19
      • 1970-01-01
      • 2015-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多