[Solved] Replacing the .ToString() Method C#


Converting an object to a string will always implicitly call the ToString method, you cannot choose a different method.

Implement your ToString method to return “true” or “false”:

class YourClass {
  public override string ToString() {
    return "true"; // or return "false"; depending on your needs.
  }
}

You can call another method explicitly though:

class YourClass {
  public string MyToString() {
    return "true"; // or return "false"; depending on your needs.
  }

  public static void Main() {
    Console.WriteLine(new YourClass().MyToString());
  }
}

solved Replacing the .ToString() Method C#