Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override ToString() in [] array?

Say, if I need to override ToString method in a custom List, I'd do this:

public class WebUILanguage2 : List<WebUILanguage>
{
    public override string ToString()
    {
        return "Overridden message";
    }
}

but what if I want to override this?

public class WebUILanguage2 : WebUILanguage[]
like image 907
ahmd0 Avatar asked Mar 21 '23 19:03

ahmd0


1 Answers

You can't. You can't derive from array types.

I'd generally advise against overriding ToString in List<T>, too - usually it's better to use composition than inheritance for things like this, in my experience.

like image 151
Jon Skeet Avatar answered Apr 02 '23 04:04

Jon Skeet