Avatar of Mr_Fulano
Mr_Fulano
Flag for United States of America asked on

Adding addtional Modules to a C# Solution.

Hi, I'm using MS VS2010, C#.NET. I currently have an application with a lot of methods all rolled up above the code for my Controls. I'd like to organize my code-behind in a more intuitive manner (at least intuitive for me) and be able to add Modules (additional Tabs) where I can put all the code that is general math related into one Tab and another Tab for all the code dealing with hexadecimal manipulations, etc. I guess I can use Namespaces, but is that the best approach. I recall in VB.NET I was able to add Modules to the application and have different modules (i.e. pages , Tabs) for different code types.

Is that possible in C#, if so how would I do that, and if not what is a better approach other than to have all my code on one page all rolled up?

Thanks,
Fulano
C#.NET Programming

Avatar of undefined
Last Comment
Mr_Fulano

8/22/2022 - Mon
SOLUTION
kaufmed

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Michael Fowler

If you are trying to make a class easier to read use regions eg
#region Math Code

//Methods related to Maths here

#endregion

Open in new window


Visual Studion allows to collapse regions and so makes it far easier to navigate your code to find what you are after.

Michael
Mr_Fulano

ASKER
Hi Michael74, yes...by "rolled up" in my original post, I mean I have them all in regions, but its still messy! I was hoping to spread things out a bit and have designated areas for certain types of code.

Thanks,
Fulano
Mr_Fulano

ASKER
Hi Kaufmed, good suggestions. I'll give that approach a try and see where I go with it.

Thanks,
Fulano
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Dmitry G

I don't like modules. Really, they exist just for backward compatibility with VB6 and prior.

I a class becomes too large - try to re-factor to separate classes. Check that no business logic in a presentation layer - move it to business classes.

Idea with regions is also good - I use it all the time.
Michael Fowler

I personally use a combination. As noted above keeping presentation and business logic seperated is always a good idea but I like to use regions to seperate code into sections eg

Public Varaibles
Private Variables
Constructors
Button Click Events
etc..

Fulano
If you are finding that some regions are getting out of hand then look at seperating these regions out into new classes. Static classes are very handy for this.

Michael
Mr_Fulano

ASKER
Hi Michael, regions is what I use now and its a bit too messy for my taste. Regions work for small areas of code, but when you begin to have 4 or 5 different methods within that region, then its too hard to keep under control.

I was thinking of Classes, but I guess the problem I'm struggling with is that a Class can be instantiated into an Object, so I'm thinking my MathClass can be instantiated into a MathClass Object, which wouldn't make any sense given that its a Class without a constructor (well...all Classes have a default constructor that really doesn't do anything), and that Class is full of methods.

Is that a good idea....?

Thanks,
Fulano
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
Michael Fowler

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Mr_Fulano

ASKER
Excellent....this is what I needed to understand. -- Static Classes is what will help me refactor my code. Thank you both!