why i can't access list in button click event when list is declared in page_load event ?

Rhishi

New member
Joined
Feb 17, 2019
Messages
2
Programming Experience
Beginner
HI everyone ! i am very new to c#.
please can anybody explain why i can't access c# list in button click event when c# list is declared in page_load event ?
 
You need to do some reading about variable scope. Every variable only exists inside the block it is declared in, with the (sort of) exception of a type field declared public. If you declare a variable inside a method then that variable exists only inside that method. If you want to be able to access the same variable from multiple methods then it needs to be declared outside all of them.
 
Back
Top Bottom