【问题标题】:How method to be moved out to a separate method如何将方法移出单独的方法
【发布时间】:2013-06-13 05:38:22
【问题描述】:

大家好,

在此我有三个参数如何将methodname.Equals('xx') 方法移出到单独的方法中。

 public static String APIMethod(string modulename,string methodname,string postContent )
    {
      string recordId = "1";
    string uri = zohocrmurl + modulename + "/"+methodname+"?";
    /* Append your parameters here */
    postContent = "scope=crmapi";
    postContent = postContent + "&authtoken=0ac32dc177c4918eca902fd290a92f4a";//Give your authtoken
//how to move this and create them as seperate methods
    **if (methodname.Equals("insertRecords") || methodname.Equals("updateRecords"))
    {
    postContent = postContent + "&xmlData="+ HttpUtility.UrlEncode("Your CompanyHannahSmithtesting@testing.com");
    }
    if (methodname.Equals("updateRecords") || methodname.Equals("deleteRecords") || methodname.Equals("getRecordById"))
    {
    postContent = postContent + "&id="+recordId;
    }**
    string result = AccessCRM(uri, postContent);
    return result;
    }

【问题讨论】:

    标签: c# c#-4.0 c#-3.0


    【解决方案1】:

    为什么不使用switch (C# Reference)

    switch 语句是选择开关的控制语句 从候选列表中执行的部分。

    【讨论】:

      【解决方案2】:

      如果xxx 部分不修改name 并且每次都不同,您可以这样做:

      public static string rest(string name, string method,string count)
      {
           switch(name.Trim().ToLower())
           {
                case: "insert":
                {
                    xxx
                    break;
                }
                case: "delete":
                {
                    xxx
                    break;
                }
                case: "update":
                {
                    xxx
                    break;
                }
      
              string result = xxx;
              return result;
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-12-05
        • 2021-02-08
        • 1970-01-01
        • 2020-12-27
        • 2012-12-25
        • 1970-01-01
        • 2020-01-25
        相关资源
        最近更新 更多