Sometimes an example helps too so for your text reading thing i guess you
have something like
public void ButtonClick(object sender, e eventArgs)
{
for(int i=0; i<numRecs; i++)
{
//get record and read it
//do all your stuff with it
//inform user
//write text file
//do something else
//etc etc etc
}
}
Reulting in a big button method. As Barry said break this down into
something logical and easy to read and keep in mind scalability and
maintenance.
Now say you do a new project and think, that code i wrote for the text
reader was good lets reuse that, you will then go into that button, copy the
code and paste to a new project. Say you use it in 6 projects and along the
way you update the code or someone else wnats to use it this is a problem.
Just one problem of many from not doing this right to be honest.
So you break it down by making a new class and create get and set methods
and so on. A good starting point to understand classes is to write a basic
calculator.
At the moment i bet you'd do something like this:
Public ButtonClick()
{
switch(choice)
{
case divide:
return x/y;
case multiply:
return x*y;
}
}
etc
But a better way is a new class called say Calculator and you'd make methods
such as these in that class
public int Add(int x, int y)
{
return x +y;
}
public int Subtract(int x, int y)
{
return x-y;
}
public int Divide(int x, int y)
{
return x/y;
}
etc
Now your button click code would become
Public ButtonClick()
{
Calculator myCalc = new Calculator();
switch(choice)
{
case divide:
return myCalc.Divide(x, y);
case multiply:
return myCalc.Multiply(x, y);
}
}
I know in this case they look very similar but the second one is much more
scalable and easier to read. So now if you did a new project and wanted to
use your calculator you need only add the Calculator clas to it and voila
you can use it as above. My example above is VERY basic but better to show
that at the stage you are at. Imagine the methods were much bigger and you
can see the benefit, Easier to read, easier to manage and if you decide to
say add a handler in the Multiply method you just go to the calculator class
and change it there and everywhere the method is called is updated.
Dunno if that helps your understanding of the basics how and why's?
<Ro********@yahoo.co.uk> wrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
Sorry I meant Areas.
Regards Robert