0

我正在尝试编写一个函数,从一个类中调用一个从接口派生的函数(ISFAction)。

区别在哪里/什么更好?

  public string Create<T>(ISFServer server, T action, string[] args) where T : ISFAction
  {
      string requestUrl = null; 
      string actionPart = action.GenerateAction(args);
      requestUrl += server.serverUri.ToString();
      requestUrl += "request.php?req=";
      requestUrl += actionPart;

      return requestUrl;
  }

还有我的另一个版本:

  public string Create(ISFServer server, ISFAction action, string[] args)
  {
      string requestUrl = null; 
      string actionPart = action.GenerateAction(args);
      requestUrl += server.serverUri.ToString();
      requestUrl += "request.php?req=";
      requestUrl += actionPart;

      return requestUrl;
  }

什么是更好的?

4

1 回答 1

2

第二个代码片段(没有泛型类型参数)更好,因为(如您在第一个代码片段中所示)泛型类型参数是无用的;它根本不使用。这只是无缘无故地使代码复杂化。

于 2013-06-12T10:47:49.107 回答