error CS0133: Assigning the result of a function to a const in C#.net
- by Greg
Trying to tidy up scope and avoid possible multiple calls to RegisterWindowMessage.
Currently have a class used once with the following member
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int RegisterWindowMessage(string lpString);
private int m_message = RegisterWindowMessage("MY_MSG");
As we only have one instance this seems ok, but think it would be more tidy to use. With my basic C# understanding this should call RegisterWindowMessage and assign the result to int and not allow it to change.
private const int message = RegisterWindowMessage("MY_MSG");
however attempting to do so leads to a
error CS0133: The expression being assigned to 'someclass.messageEvent' must be constant
so now I'm confused, does this mean the function was being assigned and called each time m_message was used previously, is there something else missing?