params SqlParameter[] commandParameters上面的定义应该如何理解?这是petshop4里面的。

解决方案 »

  1.   

    params 表示 函数 的 参数个数 不确定..
      

  2.   

    应该是  SqlParameter[] parms = SqlHelper.GetCachedParameters(SPNAME_PRODUCT_INSERT);
     if (parms == null)
       {
           parms=
           //......
           SqlHelper.SetCacheParameters(SPNAME_PRODUCT_INSERT, parms);
        }    return parms;这样吧?声名一个参数数组,根据关键字在缓存中找,如要找不到就重新构造.
      

  3.   

    params 关键字可以指定在参数数目可变处采用参数的方法参数。在方法声明中的 params 关键字之后不允许任何其他参数,并且在方法声明中只允许一个 params 关键字。示例
      复制代码 
    // cs_params.cs
    using System;
    public class MyClass 
    {    public static void UseParams(params int[] list) 
        {
            for (int i = 0 ; i < list.Length; i++)
            {
                Console.WriteLine(list[i]);
            }
            Console.WriteLine();
        }    public static void UseParams2(params object[] list) 
        {
            for (int i = 0 ; i < list.Length; i++)
            {
                Console.WriteLine(list[i]);
            }
            Console.WriteLine();
        }    static void Main() 
        {
            UseParams(1, 2, 3);
            UseParams2(1, 'a', "test");         // An array of objects can also be passed, as long as
            // the array type matches the method being called.
            int[] myarray = new int[3] {10,11,12};
            UseParams(myarray);
        }
    }
     输出
      
    1
    2
    31
    a
    test10
    11
    12
     
      

  4.   

    和SqlParameter[] commandParameters差不多吧