I need to use an Enum for readability and as Type string.

Ronald Rex 1,526 Reputation points

I have this Enum that I am using along with an extension method. And I was just wondering if I should be able to assign an Error Level to a string variable like so..... string id = ErrorLevel.Low. For some reason I am getting a compile error... A value of type 'ErrorLevelExtensions.ErrorLevel' cannot be used as a default parameter because there are no standard conversions to type string. I thought my extension method returns a string?!?

public enum ErrorLevel

public static class ErrorLevelExtensions
  public static string ToFriendlyString(this ErrorLevel me)
      case ErrorLevel.None:
        return "Everything is OK";
      case ErrorLevel.Low:
        return "SNAFU, if you know what I mean.";
      case ErrorLevel.High:
        return "Reaching TARFU levels";
      case ErrorLevel.SoylentGreen:
        return "ITS PEOPLE!!!!";
        return "Everything is Fine";
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,502 questions
0 comments No comments
{count} votes

Accepted answer
  1. P a u l 9,976 Reputation points

    An extension method is just a method that you can call on a type, not a method that does an implicit conversion to another type.

    You can call it explicitly though:

    string id = ErrorLevel.Low.ToFriendlyString();

0 additional answers

Sort by: Most helpful