D G

D G

  • NA
  • 14
  • 8.6k

To increase the speed of excution for a method in c#

Aug 20 2014 11:48 PM
Please help me to write the method in optimized way, so that it takes less time to execute. Mine is as given below , which takes bit long time to execute. Please help me ASAP.Thanks in advance. 

  public Dictionary<string, List<double>> GetTotalLengt_VolumehofMemberUsed_AlongStaadName()
        {
            Dictionary<string, List<double>> memberData = new Dictionary<string, List<double>>();
            Dictionary<string, List<int>> sec_Dict = _sectionDetails.GetAllMemberIDsWithinATable();


            double _memLength = 0.0; double _totalMemLength = 0.0;
            double _memVolume = 0.0; double _totalMemVolume = 0.0;


            double[] _memArray;
            Dictionary<int,double> _memList = new Dictionary<int,double>();


            foreach (string s in sec_Dict.Keys)
            {
                List<int> _valueList = sec_Dict[s];


                foreach (int n in _valueList)
                {
                    _memLength = this.Getlengthofmember(n);
                    _memList.Add(n, _memLength);
                    _totalMemLength += _memLength;
                    _memVolume = this.GetVolumeofmember(n);
                    _totalMemVolume += _memVolume;
                }


                this.STAAD_NAME = s;
                this.TOTAL_MEMBER_LENGTH = Math.Round(_totalMemLength, 4);
                this.TOTAL_MEMBER_VOLUME = Math.Round(_totalMemVolume, 4);




                if (_memList != null)
                {
                    _memArray = new double[_memList.Count];
                    foreach (KeyValuePair<int, double> d in _memList)
                    {
                        _memArray = _memList.Values.ToArray();
                    }




                    if (_memArray != null && _memArray.Length > 0)
                    {
                        this.LONGEST_MEMBER_ID = _memList.FirstOrDefault(x => x.Value.Equals(_memArray.Max())).Key;
                        this.LONGEST_MEMBER_LENGTH = _memArray.Max();
                        this.SHORTEST_MEMBER_ID = _memList.FirstOrDefault(x => x.Value.Equals(_memArray.Min())).Key;
                        this.SHORTEST_MEMBER_LENGTH = _memArray.Min();
                    }
                }




                List<double> list = new List<double>();
                list.Add(this.TOTAL_MEMBER_LENGTH);
                list.Add(this.TOTAL_MEMBER_VOLUME);
                list.Add(this.LONGEST_MEMBER_ID);
                list.Add(this.LONGEST_MEMBER_LENGTH);
                list.Add(this.SHORTEST_MEMBER_ID);
                list.Add(this.SHORTEST_MEMBER_LENGTH);
                memberData.Add(this.STAAD_NAME, list);


            }


            return memberData;
        }


Please can anyone help me on this quickly.





Answers (1)