当前位置: 首页>>代码示例>>C#>>正文


C# TimeSpan.ToList方法代码示例

本文整理汇总了C#中System.TimeSpan.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSpan.ToList方法的具体用法?C# TimeSpan.ToList怎么用?C# TimeSpan.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.TimeSpan的用法示例。


在下文中一共展示了TimeSpan.ToList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SnugArray

        private SnugArray(Dictionary<TimeSpan, ParentIDCount> EntryArrayOfStuff, TimeSpan MaxValue, List<Dictionary<string, int>> MyListOfDicts)
        //private SnugArray(List<TimeSpanWithID> ConstrainedElements,List<TimeSpanWithID> EntryArrayOfStuff, TimeSpan MaxValue,List<Dictionary<string, int>> MyListOfDicts)
        //private SnugArray(List<TimeSpanWithID> ConstrainedElements,List<TimeSpanWithID> EntryArrayOfStuff, TimeSpan MaxValue,Dictionary<string, int> MyDict,List<Dictionary<string, int>> MyListOfDicts)
        {

            EntryArrayOfStuff = new Dictionary<TimeSpan, ParentIDCount>(EntryArrayOfStuff);
            ArrayOfStuff = EntryArrayOfStuff;
            int i=0;
            maxTimeSpan = MaxValue;
            List<TimeSpan> EventKeys = EntryArrayOfStuff.Keys.ToList();


            List<TimeSpan> SmallerElements = new List<TimeSpan>();
            i = 0;
            int MyArrayCount = EventKeys.Count;
            ListOfDictionaryOfID_Count = MyListOfDicts;
            for (; i < MyArrayCount; i++)//loop gets element only smaller or equal to max size
            {
                ParentIDCount MyEntry = EntryArrayOfStuff[EventKeys[i]];
                if ((MyEntry.Item2 <= MaxValue)&&(MyEntry.Item1 >0))//checks if smaller than max value
                {
                    SmallerElements.Add(EventKeys[i]); 
                }
            }
            int IncludeOrDontIncludeLastElement = 0;
            if (SmallerElements.Count > 1)
            {
                int counter = SmallerElements.Count;
                TimeSpan TotalSumOfTimeSoFar = new TimeSpan(0);
                for (; counter > 0;counter-- )//including the index 0 in for loop means index is small enough to include all indexes
                {
                    TimeSpan KeyToLastElement = SmallerElements[counter - 1];
                    ParentIDCount CurrentParentIDCOunt = EntryArrayOfStuff[KeyToLastElement];
                    TotalSumOfTimeSoFar += TimeSpan.FromTicks(CurrentParentIDCOunt.Item2.Ticks * CurrentParentIDCOunt.Item1);
                    TimeSpan TimeSpanDiff = MaxValue - TotalSumOfTimeSoFar;
                    if (TimeSpanDiff >= EntryArrayOfStuff[SmallerElements[0]].Item2)
                    {
                        ++IncludeOrDontIncludeLastElement;
                    }
                    else 
                    {
                        break;
                    }
                }
            }

            TopElements = SmallerElements.ToArray();
            //int LengthOfSubElmentArray = TopElements.Length;
            

            i = 0;

            TimeSpan[] MyFittableElemtsHolder = new TimeSpan[SmallerElements.Count];//Array holds the current array of subelements for future reasons
            List<TimeSpan> MyFittableElementsHolderList = new List<TimeSpan>();//This is also holds a curent array of sub elements.
            SmallerElements.CopyTo(MyFittableElemtsHolder, 0);
            MyFittableElementsHolderList = MyFittableElemtsHolder.ToList();
            MyArrayCount = SmallerElements.Count - IncludeOrDontIncludeLastElement;
            SubSnugArrayElements = new SnugArray[MyArrayCount];
            Tuple<Dictionary<TimeSpan, ParentIDCount>, TimeSpan, List<Dictionary<string, int>>>[] PreppedDataArray = new Tuple<Dictionary<TimeSpan, ParentIDCount>, TimeSpan, List<Dictionary<string, int>>>[MyArrayCount];
            
            MyDict = EntryArrayOfStuff;

            Dictionary<TimeSpan, ParentIDCount> EntryArrayOfStuff_Cpy = new Dictionary<TimeSpan, ParentIDCount>(EntryArrayOfStuff);




#if enableMultithreading

            int j = 0;
            for (; j < MyArrayCount; j++)//prepares data for multithreading breaks dependent references
            {
                
                ParentIDCount DictEntry = EntryArrayOfStuff_Cpy[TopElements[j]];
                DictEntry = DictEntry.CreateCopy;
                --(DictEntry.Item1);
                EntryArrayOfStuff_Cpy[TopElements[j]] = DictEntry;

                Tuple<Dictionary<TimeSpan, ParentIDCount>, TimeSpan, List<Dictionary<string, int>>> PreppedData = new Tuple<Dictionary<TimeSpan, ParentIDCount>, TimeSpan, List<Dictionary<string, int>>>(EntryArrayOfStuff_Cpy, (MaxValue - DictEntry.Item2), ListOfDictionaryOfID_Count);//creates new snug array with elements that are smaller
                PreppedDataArray[j] = PreppedData;
                EntryArrayOfStuff_Cpy.Remove(TopElements[j]);
            }





            Parallel.For(0, MyArrayCount, k =>//makes parallel calls
            {
                
                if (k > 0)
                {
                    EntryArrayOfStuff_Cpy.Remove(TopElements[j - 1]);
                }


                Tuple<Dictionary<TimeSpan, ParentIDCount>, TimeSpan, List<Dictionary<string, int>>> PreppedData0 = PreppedDataArray[k];
                SubSnugArrayElements[k] = new SnugArray(PreppedData0.Item1, PreppedData0.Item2, PreppedData0.Item3);//creates graph on current node

            }
//.........这里部分代码省略.........
开发者ID:jerbio,项目名称:My24HourTimerWPF,代码行数:101,代码来源:SnugArray.cs


注:本文中的System.TimeSpan.ToList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。