views:

213

answers:

1

I have a method group that contains elements such as:

class Foobar
{
    public static DataSet C(out string SpName)
    {
        SpName = "p_C";
        return null;
    }

    public static DataSet C()
    {
        string SpName;
        C(out SpName);
        return DataAccess.CallSp( SpName);

    }
}

And what I want to do is

 ButtonC.Text = DataAccess.GetSpName(**?????** Foobar.C )

where I want to do this action:

 public string GetSpName(**(?????)** method)
 {
     string spName = string.Empty;
     method(out spName);
     return spName;
 }

I have tried various items as ????? without success. I'm missing some fine point :-(

+2  A: 

You need to declare a delegate:

// A delegate that matches the signature of
// public static DataSet C      (out string SpName)
public delegate  DataSet GetName(out string name);

public class DataAccess
{
   // ...

   static public string GetSpName(GetName nameGetter)
   {
       // TODO: Handle case where nameGetter == null
       string spName;
       nameGetter(out spName);
       return spName;
   }

   // ...
}

// ...

public void SomeFunction()
{
    // Call our GetSpName function with a new delegate, initialized
    // with the function "C"
    ButtonC.Text = DataAccess.GetSpName(new GetName( Foobar.C ))
}
Daniel LeCheminant