如何比较列表< List< Myclass>>随着每个索引

编程入门 行业动态 更新时间:2024-10-28 08:29:48
本文介绍了如何比较列表< List< Myclass>>随着每个索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的代码

here is my code

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; } }

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是我已经找到它的关键路径我只是想告诉你我什么时候创建的一类。如果我想比较Cri_Finder [0] [0]和Cri_Finder [1] [0] Cri_Finder [2] [0]。 Cri_finder [0] [0] Crifider [1] [0] Crifider [2] [1]<<<<<<<最后一个list'index将增加我怎么能这样做:( PS:如果我的英语不好我很抱歉我喜欢A [0] [0] >>> A [1] [0]>> A [2] [0]并且nex将是A [2] [1]并且nex将是A [2] [2]直到A [2]的最后一个列表是这样的:(

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 :(

推荐答案

我修改了你的代码以保持我的早先的建议。我认为你还需要考虑使用多个数组不是一个好习惯。你可能想要用数据结构(如List或Dictionary)替换所有数组。我没有在随后的代码。

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. 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.

更多推荐

如何比较列表&lt; List&lt; Myclass&gt;&gt;随着每个索引

本文发布于:2023-11-11 11:50:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578358.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:索引   列表   amp   List   lt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!