Click here to Skip to main content
15,889,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my code

C#
class activity
{
   public string PName { get; set; }
   public int Duration { get; set;}
   public int Cost { get; set;}
   public int Rush_Duration { get; set;}
   public int Rush_Remain { get; set;}

   public activity(string PName, int Duration, int Cost, int Rush_Duration, int Rush_Remain)
   {
      this.PName = PName;
      this.Duration = Duration;
      this.Cost = Cost;
      this.Rush_Duration = Rush_Duration;
      this.Rush_Remain = Rush_Remain;
   }
}


C#
for (int i = 0; i < WayFinder.Count; i++)
{
   List<activity> sub = new List<activity>();
   for (int ii = 0; ii < WayFinder[i].Count; ii++)
   {
      for (int iii = 0; iii < Proj_name_Values.Count; iii++)
      {
         if (WayFinder[i][ii] == Proj_name_Values[iii])
         {
            int P = 0;
            P = Duration_Value2[iii] - RustPredecessorlimite[iii];
            if (CostPerDat[iii] == "")
            {
               CostPerDat[iii] = "9999999";
            }
            activity a = new activity(Proj_name_Values[iii], Duration_Values[iii], Convert.ToInt32(CostPerDat[iii]), RustPredecessorlimite[iii], P);
            acti.Add(a);
         }
      }
   }
   for (int K = 0; K < acti.Count; K++)
   {
      sub.Add(acti[K]);
   }
   Cri_Finder.Add(sub);
   acti.Clear();
}


well way_fider are Critical path that i already find it out i just want to tell you that when did i create a class. if i want to compare Cri_Finder[0][0] and Cri_Finder[1][0] Cri_Finder[2][0] . Cri_finder[0][0] Crifider[1][0] Crifider[2][1] <<<<<<< the last list'index will increase how can i do that : (

PS: if my english is bad i am sorry i kid like A[0][0] >>> A[1][0] >> A[2][0] and the nex one will be A[2][1] and the nex will be A[2][2] till the last of A[2] list something like that :(
Posted
Updated 25-May-14 22:27pm
v2
Comments
gggustafson 26-May-14 15:05pm    
Sawaddeekap.

Why is CostPerDat a string? It should be an int. If you want to assign a large value, use INT_MAX.

Your algorithm is at best confused. Why are you not just adding items to Cri_Finder instead of going through a, acti, and Sub?

Suggestions:

Rename Way_Finder to critical_path; ii to row; iii to columns; P is a difference, name it difference, etc.

1 solution


I have revised you code in keeping with my earlier suggestions. I think that you also need to consider that the use of multiple array is not a good practice. You might want to replace all of the arrays with a data structure (like List or Dictionary). I did not do that in the code that follows.


C#
using System.Collections.Generic;
using System.Windows.Forms;

namespace CompareIndexWith_List
    {

    public partial class Form1 : Form
        {
        int [ ]             cost = new int [ 20 ];
        string [ ] [ ]      critical_path = new string [ 300 ] [ ];
        int [ ]             duration = new int [ 20 ];
        int [ ]             predecessor_limits = new int [ 20 ];
        string [ ]          project_names = new string [ 20 ];

        List < activity >   Cri_Finder = new List < activity > ( );

        // ***************************************************** Form1

        public Form1 ( )
            {
            InitializeComponent ( );

            // fill cost
            //      critical_path
            //      duration
            //      predecessor_limits
            //      project_names
            }

        // ******************************************* fill_Cri_Finder

        void fill_Cri_Finder ( )
            {

            for ( int row = 0; ( row < critical_path.Length ); row++ )
                {

                for ( int column = 0; 
                        ( column < critical_path [ row ].Length ); 
                          column++ )
                    {
                    for ( int i = 0; i < project_names.Length; i++ )
                        {
                        if ( critical_path [ row ] [ column ].Equals ( 
                                 project_names [ i ] ) )
                            {
                            int difference = 0;

                            difference = duration [ i ] - 
                                         predecessor_limits [ i ];
                            if ( cost [ i ] == 0 )
                                {
                                cost [ i ] = int.MaxValue;
                                }
                            Cri_Finder.Add ( 
                                       new activity ( 
                                           project_names [ i ], 
                                           duration [ i ], 
                                           cost [ i ], 
                                           predecessor_limits [ i ], 
                                           difference ) );
                            }
                        }
                    }
                }
            }

        } // class Form1

    // ************************************************ class activity

    class activity
        {
        public string   ProjectName { get; set; }
        public int      Duration { get; set; }
        public int      Cost { get; set; }
        public int      RushDuration { get; set; }
        public int      RushRemainder { get; set; }

        public activity ( string project_name, 
                          int    duration, 
                          int    cost, 
                          int    rush_duration, 
                          int    rush_remainder )
            {

            ProjectName = project_name;
            Duration = duration;
            Cost = cost;
            RushDuration = rush_duration;
            RushRemainder = rush_remainder;
            }

        } // class activity

    } // namespace CompareIndexWith_List


Hope that helps.

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900