Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 扩展方法中的可选字符串参数_C#_Extension Methods_Optional Arguments - Fatal编程技术网

C# 扩展方法中的可选字符串参数

C# 扩展方法中的可选字符串参数,c#,extension-methods,optional-arguments,C#,Extension Methods,Optional Arguments,我有一行代码,上面写着 string sendQueueName = ESResource.Service.TOPICA.Src(); 课程的布局方式如下所示:- public static class ESResource{ static ESResource() { //initialization code } //other declarations and definitions public enum Service { TOPICA,TO

我有一行代码,上面写着

string sendQueueName = ESResource.Service.TOPICA.Src();
课程的布局方式如下所示:-

public static class ESResource{
    static ESResource() {
        //initialization code
    }
//other declarations and definitions

    public enum Service { TOPICA,TOPICB,TOPICC };
    public static string Path(this Service sn) { return FromKey(sn, "PATH"); }
    public static string Src(this Service sn) { return FromKey(sn, "SRC"); }
}
我有一个功能,需要我能够传递一个字符串env 像这样

string sendQueueName = ESResource.Service.TOPICA.Src(env);
但当我试图修改Src函数以支持上述函数调用时,如下所示:

public static string Src(this Service sn, string env=""){ return FromKey(sn, "PATH", env); }

它说它找不到一个只有一个参数的函数。传入可选参数env的最佳方式是什么?

您发布的代码没有多大意义。如何可以有两个ESResource类?什么是TPSDevirativeSqueue?重载。。。。不要修改你的Src函数,创建另一个。很抱歉输入错误。请看编辑@Ben Voigt..我也试过了,但是我得到了一个错误,方法'Src'没有重载需要1个参数。我做得对吗?公共静态字符串Srcthis Service sn,string env{return FromKeysn,SRC,env;}@AnushaPachunuri:看起来不错。你能在ideone.com或其他在线编译器上提供一个完整的最小示例吗?FromKey方法看起来像什么?