In terms of variable scope, there are a lot of things to do based on the level of exposure you want to give your variables. In my practise, I usually use the following :
1. the
ref
keyword : when I want to give my methods a wide scope within the whole class without re-creating them within each method, since by default methods encapsulate their member variables and make it accessible only within the method.
2.
properties : which will create encapsulation of a variable and give you the power to limit how your users will use the variable (either a
getter scope,
setter scope or both)..Eg.
int emp_name;
public int Emp_Name
{
get
{
return emp_name;
}
set
{
emp_name=value;
}
}
3.
Interfaces : And this is what I sometimes love using especially when I want to limit variable access
.
.
interface _InterfaceName
{
void getData();
void sendData(string _arg1, int _arg2);
}
class Implementer : _interfaceName
{
public void getData()
{
}
public void sendData(string _arg1, string _arg2)
{
}
}