C#Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Hi evryone
Tis is my first message in wrox P2P:)
In WINDOWS APPLICATIONS for example in Classes when I declare a global variable(like int a=0;)
and use this variable in different procedures for example I change the value in one procedure(procedure 1)(like a=1;) and when in another procedure(procedure 2) I want to obtain the value it is correct(I mean a is 1 not 0 or null)...but....
in ASP.NET APPLICATIONS if I do this method just like above the value is not correct
(in asp.net application in procedure 2 a is 0 not 1 )
if I use another type of variables like string or even classes the results are the same.
I can not get why...
Could someone explain it...
With thanks and regards.
If you are trying to share the same value among forms, modules, classes, etc., you need to declare the global variable as static in C#. That will make the value the same among all procedures.
Can you describe what you are intending to do with these global variables? This may provide us more information to determine what is "not working". Working with globals can be tricky depending on the situation. You should try to avoid them as much as possible. It's possible that what you are tryig to achieve can not be done the way you think it can and that there is a better way of doing it in ASP.NET.
>Can you describe what you are intending to do with these global variables?
I have a DataAdapter object for working on my database. you know in evry procedure the adapter should be recreated .I don't want to do that(I mean recreating adapter in evry procedure)
finaly by declaring my adapter as a static global varable my problem has been solved.but because of security reasons It will not be a good manner
I think recarating it in evry procedure is a better way
but for other ordinary global variables by declaring them as static they behave really globally in ASP.NET applications
any idea?
is sthere any better ways?
Thanks to bmains and planoie.