String interpolation outputs enum name instead of value
You just need to use a format string in the interpolated value to force the result to integer format.
Dim sDateModified As String
sDateModified = $"<div name='commenttype{CommentType.MyComment:D}'></div>"
You're getting the string value MyComment
because that's what is returned by:
CommentType.MyComment.ToString()
Methods like String.Format
and Console.WriteLine
will automatically call ToString()
on anything that isn't already a string. The string interpolation syntax $""
is just syntactic sugar for String.Format
, which is why string interpolation also behaves this way.
Your workaround is correct. For slightly more compact code, you could do:
CInt(CommentType.MyComment)