| |

VerySource

 Forgot password?
 Register
Search
View: 659|Reply: 2

When defining global variables in the background of the page, should they be defined as protected or private?

[Copy link]

7

Threads

16

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-11-4 09:30:01
| Show all posts |Read mode
E.g:
public partial class CalcYear: System.Web.UI.Page
{
    protected int total = 0;
    protected void Page_Load(object sender,EventArgs e)
    {
if(!Page.IsPostBack)
{///Bind control data
   BindVisitData();
}
    }
    ......
}

Just like the sentence protected int total = 0;, sometimes private int total = 0; is also useful. I don’t know which one to use, or it doesn’t matter. Please expert advice, thank you!
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-11-4 14:15:01
| Show all posts
If you call in a page (.aspx) such as: <%= total %>, it can be protect
If not called, it is private
Reply

Use magic Report

7

Threads

16

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

 Author| Post time: 2020-11-4 14:45:01
| Show all posts
I even saw:

int nMailID = -1;
public total = 0;

Global variables declared in this way. How do they explain? Thank you!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list