error CS0133: Assigning the result of a function to a const in C#.net
Posted
by Greg
on Stack Overflow
See other posts from Stack Overflow
or by Greg
Published on 2010-05-26T20:21:24Z
Indexed on
2010/05/26
20:31 UTC
Read the original article
Hit count: 426
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?
© Stack Overflow or respective owner