This is a general problem I have always had trying to understand how C# is meant to be used. It might be that there is some silly syntax mistake I always make, so I think I can't do something, or it could be failure to get it at all.
I write a program to do something. It has a few classes with their variables and methods etc and it has one class which contains Main(). Pretty much the only thing in that class is Main().
I develop the program to do what ever it is meant to do and eventually I get it to work. When I've finished Main() might be a few hundred lines long and has a whole bunch of variables and some code controlling instantiations of classes.
And that is all fine except I don't like the look of the long piece of code in Main(). It is too big to follow easily and maybe has a couple of big nested loops etc. Additionally I might decide that now its working I'd like to loop through the whole thing with different options or whatever.
So, I want to take some of the bigger chunks of code in Main() which have specific purposes and turn them into new methods. That way the code will by much easier to understand and adjust.
And this is where it goes wrong for me, I can't seem to work out how, in general, you are meant to partition the Main() method into several new methods.
* You can't define methods at all within Main(), it seems that just isn't allowed - or am I wrong????
* If you put the new methods into an existing class, the class needs access to all the variables and methods previously in Main() i.e. it needs to contain them. It might be the case that sometimes this makes sense but in general it is probably no good because they don't really belong there and also Main() then has to access them through the class instance.
* You could put the data and new methods into another new class. This would be like a program flow control class. But does anyone do that? It just seems clunky. And main still has to access them through the class instance. It just strikes me that I am moving all the stuff I expect to find in Main() into another class, just so that I can make some local methods. In the end Main() won't have any purpose other to instantiate and run the other class. This just can't be what was intended - or is it????
* You can put the data and new methods into the class which contains Main(). But this is really just a special case of the previous option, the data might be in the same class as Main() but it still has to be accessed through a class instantiation.
Have I missed some basic point or what?
Thanks in advance.
=============================================================================
I'm having to reply here because "reply" doesn't seem to work for me...
Thanks so much for your response. I feel a lot better about it now. I have several books in fact, I don't know if they are good or not but I think they are acceptable. What has caused me the confusion is that the books are restricted to smallish programs and so the reader never sees my problem arising, everything can go into Main() and that's just dandy. But when I go on a spree and Main() gets over a certain size, I just begin to think, hang on, this can't be right.