3

I am converting a working .NET 3.5 application to .NET 4.0 and after changing the target framework I'm getting an error I've never seen before.

Member 'string.Join(string, params string[])' cannot be accessed with an instance reference; qualify it with a type name instead.

Here is the code:

/// <summary>
/// 
/// </summary>
/// <returns>command arguments as single line</returns>
public virtual string ToLine()
{
    List<string> argumentsList = new List<string>();
    CollectArguments(argumentsList);
    String args = null;
    foreach (string s in argumentsList)
        args = args.Join(" ", s);

    return ComandName().Join(" ", args);            
}

Obviously something changed from 3.5 to 4.0 but I'm having a hard time figuring out how I should modify this code to get it to compile.

4

2 回答 2

7

Join是一个静态方法String,所以使用类型而不是像这样的实例调用它

args = string.Join(" ", s);
于 2012-04-13T19:59:27.063 回答
2
    public virtual string ToLine()
    {
        List<string> argumentsList = new List<string>();
        CollectArguments(argumentsList);
        String args = null;
        args = string.Join(" ", argumentsList);
        return string.Join(" ", ComandName(), args);
    }
于 2012-04-13T20:00:49.687 回答