Why do I get “cannot be accessed with an instance reference” when using teststring.Join but not teststring.Split? (c#)

前端 未结 6 503
南旧
南旧 2021-01-18 11:44

I\'m learning c# and there is something I do not understand that I\'ve been unable to find any help about online.

string[] = testarray = { \"test1\", \"test2         


        
6条回答
  •  执笔经年
    2021-01-18 12:10

    You can look at MSDN's documentation for the String class for a list of all available methods. Static methods have an orange "S" icon next to them, while instance methods do not, e.g.:

    alt text

    When thinking about the difference between static and instance methods, think about whether the functionality of that method depends on a particular instance of the class.
    If the answer is yes, then it's likely to be implemented as an instance method; and if not, it's likely to be a static method.
    For example, the Split method separates a specific instance of the String class (the string from which it is called) into an array.
    In contrast, the Join method is like a utility method, which can be called upon to combine an array separated by a string -- without first creating an instance of the String class in order to call it.

提交回复
热议问题