• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 446
  • Last Modified:

How to divide a large program into smaller programs in C #?

I have the class form1 with 2300 lines.
What would be the best way to divide into smaller programs?

0
ocaccy
Asked:
ocaccy
6 Solutions
 
strickddCommented:
You can modularize your code by putting some of the functionality into a class file.

You can create a project for each main portion of your application and create the associated controls and then show/hide them from the main form as needed.

A lot of it depends on what exactly those 2300 lines are and what they do.
0
 
TommySzalapskiCommented:
Why do you want to put it in smaller programs? 2300 lines isn't really very much. Splitting into multiple programs and trying to link them later will be much more complicated.

Are you trying to split into multiple programs or just multiple files? You can break code into as many files as you want and just build them all at the same time. That is a good way to organize (if there's a sensible way to split). Much better than separate programs.

But, again, 2300 lines isn't really very much.
0
 
ocaccyAuthor Commented:
Very grateful for answers, I'm User trial yet, but I'm doing home here.

My purpose is to organize my code, to improve the maintenance and understanding.

For example, declarations of variables, arrays and constants can be in another X.cs and be called within the form1, in case my main class?

We have the arrays below.

They are like public and the data will for the first 6

public string [,] a_i_id_0x = new string [240, 4];

by this method:

public void logFile_writeLine1 (string stringout)
{}

In the method:
 
Sagya void ()
{}
, We get the data filled in logFile_writeLine1 array (), we make some equations, and pass the results to:

public int [,] a_i_sagyoux = new int [240, 18];

We can put these methods in other classes that the data will continue to flow?
#region Declaring the ArrayList and Arrays
        ArrayList lines = new ArrayList();

        public DateTime[] a_D_data = new DateTime[240];
        public double[] a_d_index = new double[240];
        public string[,] a_i_id_01 = new string[240, 4];
        public string[,] a_i_id_02 = new string[240, 4];
        public string[,] a_i_id_03 = new string[240, 4];
        public string[,] a_i_id_04 = new string[240, 4];
        public string[,] a_i_id_05 = new string[240, 4];
        public string[,] a_i_id_06 = new string[240, 4];
        public string[,] a_i_sagyou1 = new string[240, 18];
        public string[,] a_i_sagyou2 = new string[240, 18];
        public string[,] a_i_sagyou3 = new string[8, 18];
        public string[,] a_i_sagyou4 = new string[8, 18];
        public string[,] a_i_sagyou5 = new string[7, 7];
        public string[,] a_i_sagyou6 = new string[8, 8];
        public string[,] a_i_planilh = new string[240, 120];

        Font origFont;
        Font monoFont;

        #endregion

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
TommySzalapskiCommented:
If you want to split your class up into multiple files just use the partial keyword
public partial class Form1

You can put as many of these as you want into the same project.

If you have code that is not fully dependent on the stuff in Form1, then you can always break it into different classes.
0
 
ocaccyAuthor Commented:
I do not know how to use it.

How do you do?

Creates a class named xx1.cs and places:
namespace NanoFX
{
     public partial class Form1: Form
     {.....

Create another class named xx2.cs and places:
namespace NanoFX
{
     public partial class Form1: Form
     {.....
?
0
 
PCableGuyCommented:
ocaccy,

Which IDE are you using to make your C# project?

The reason I ask is there are probably tutorials on the Internet that will give step-by-step instructions on how to add a  Class to your project.
0
 
ocaccyAuthor Commented:
Visual Studio 2010 Ultimate!

Thank you PCableGuy.

Regards,
ocaccy
0
 
TommySzalapskiCommented:
I would do it just like you suggested except you are creating files named xx1.cs not classes. In VS, you click on the project menu and select "Add new item" then pick .cs and name it.
0
 
ocaccyAuthor Commented:
I did as you taught, then created this class.

Put in place of  class forra1, public partial class Form1, the right way?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Nanoflex
    {
       class forra1
        {
        }
    }

Open in new window

0
 
TommySzalapskiCommented:
Make sure the namespace is the same, but that should work. I didn't want you to make a new class, just a new file, but I think it will work anyway.
0
 
ocaccyAuthor Commented:
Tommy, I place code in another file and come back to tell you.
0
 
ocaccyAuthor Commented:
I believe, I can split my code with the informations.
Thank you.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now