is it possible to disable implicit ToString() call?
c#
Solution
There is no way to prevent this code at compile time. `Object.ToString` is a part of the public contract of every object and there are no ways to prevent it from being invoked at compile time. In this particular case the compiler will resolve the `+` to `String.Concat(object, object)` and the implementation ends up invoking `Object.ToString`. There is no way to change this. I think your smoothest path forward is to override `ToString` and have it call into `FormatAddress`
Please do not change `ToString` to throw an exception as a few others are suggesting. The majority of .Net expects that `ToString` exists and is non-throwing. Changing that will have many unexpected negative side effects to your program (including killing the debug experience for those objects)
Problem
I'm wondering if there is a way to get a compilation error for this code: ``` var customer = new SomeCustomerClass(); Console.WriteLine("Customer address:" + customer); ``` so I will be forced to write something like this: ``` var customer = new SomeCustomerClass(); Console.WriteLine("Customer address:" + customer.FormatAddress()); Console.WriteLine("Customer accounts:" + customer.FormatAccounts()); ``` If "ToString" would be an interface, I could do that using explicit interface implementation in my class. Thanks.