static variable value lost in webrole
> public class WebRole : RoleEntryPoint
> {
> public static int x;
> publi开发者_如何学编程c override bool OnStart()
> {
> x=5;
> return base.OnStart();
> }
> }
If I try to get WebRole.x value it is 0, even though it was initialized to 5 in the OnStart method. How is this possible?
What are you trying to accomplish? Just checking as there may be a better method in windows azure.
And I'm only theorizing here, but I'm guessing that when you go to retrieve the value, you're actually getting a new copy of the object that resides in a seperate process. As such, the value of the object instance that you set during role startup isn't accessible.
A static
field does not belong to the instance of the object. Remove static
.
精彩评论