Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string.Join throws an exception

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.

like image 206
Chev Avatar asked Apr 24 '26 03:04

Chev


1 Answers

Join is a static method on String, so call it using the type instead of an instance like this

args = string.Join(" ", s);
like image 113
Brian Rasmussen Avatar answered Apr 26 '26 16:04

Brian Rasmussen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!