18

Trying to get the underlying Integer value for my enum returned as a String.

Tried

return ((int) MyEnumValue).ToString;

But fails with

Error 1 Cannot convert method group 'ToString' to non-delegate type 'string'. Did you intend to invoke the method?

2
  • 7
    Well, did you intend to invoke the method? Method invocations always have a () in C#. If you intended to invoke the method then invoke the method. Commented Mar 7, 2011 at 6:10
  • You are missing the parenthesis at the end of ToString method call. it should be ToString(); Commented Mar 7, 2011 at 6:16

2 Answers 2

49

The less parentheses option is:

return MyEnumValue.ToString("d");
Sign up to request clarification or add additional context in comments.

2 Comments

When availible, i always go for the least parentheses stackoverflow answer
And here I am 4 years later, googling the same thing, finding out that i have commented on the same answer previously. See you again in 4 years!
12

If your method return a string and not Func<string> you need () to actually execute the method.

return ((int) MyEnumValue).ToString();

1 Comment

hahahahahahahah, well now I feel like a dick.... Sorry ex VB programmer here trying to change his ways...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.