當前位置: 首頁>>代碼示例>>C#>>正文


C# Dictionary.Clear方法代碼示例

本文整理匯總了C#中Model.Dictionary.Clear方法的典型用法代碼示例。如果您正苦於以下問題:C# Dictionary.Clear方法的具體用法?C# Dictionary.Clear怎麽用?C# Dictionary.Clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Model.Dictionary的用法示例。


在下文中一共展示了Dictionary.Clear方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: UpdateNumbersAndDistances

        private void UpdateNumbersAndDistances(SelectionScope scope)
        {
            ////////////////////////////////////////////////////////////////////////////////////
            // update numbers
            ////////////////////////////////////////////////////////////////////////////////////
            int chapter_number = 1;
            int verse_number = 1;
            int word_number = 1;
            int letter_number = 1;
            if (this.chapters != null)
            {
                // update verse/word/letter numbers
                foreach (Chapter chapter in this.chapters)
                {
                    chapter.Number = chapter_number++;

                    int verse_number_in_chapter = 1;
                    int word_number_in_chapter = 1;
                    int letter_number_in_chapter = 1;
                    foreach (Verse verse in chapter.Verses)
                    {
                        verse.Number = verse_number++;
                        verse.NumberInChapter = verse_number_in_chapter++;

                        int word_number_in_verse = 1;
                        int letter_number_in_verse = 1;
                        foreach (Word word in verse.Words)
                        {
                            word.Number = word_number++;
                            word.NumberInChapter = word_number_in_chapter++;
                            word.NumberInVerse = word_number_in_verse++;

                            int letter_number_in_word = 1;
                            foreach (Letter letter in word.Letters)
                            {
                                letter.Number = letter_number++;
                                letter.NumberInChapter = letter_number_in_chapter++;
                                letter.NumberInVerse = letter_number_in_verse++;
                                letter.NumberInWord = letter_number_in_word++;
                            }
                        }
                    }
                }
            }
            ////////////////////////////////////////////////////////////////////////////////////

            ////////////////////////////////////////////////////////////////////////////////////
            // update positions and distances
            ////////////////////////////////////////////////////////////////////////////////////
            // foreach chapter: no repeated chapters so no distances to previous same chapter

            // foreach verse: calculate distance to its previous occurrence
            Dictionary<string, int> verse_previous_verse_numbers = new Dictionary<string, int>();
            Dictionary<string, int> verse_previous_chapter_numbers = new Dictionary<string, int>();

            // foreach word: calculate distance to its previous occurrence
            Dictionary<string, int> word_previous_word_numbers = new Dictionary<string, int>();
            Dictionary<string, int> word_previous_verse_numbers = new Dictionary<string, int>();
            Dictionary<string, int> word_previous_chapter_numbers = new Dictionary<string, int>();

            // foreach letter: calculate distance to its previous occurrence
            Dictionary<char, int> letter_previous_letter_numbers = new Dictionary<char, int>();
            Dictionary<char, int> letter_previous_word_numbers = new Dictionary<char, int>();
            Dictionary<char, int> letter_previous_verse_numbers = new Dictionary<char, int>();
            Dictionary<char, int> letter_previous_chapter_numbers = new Dictionary<char, int>();

            if (this.chapters != null)
            {
                foreach (Chapter chapter in this.chapters)
                {
                    if (scope == SelectionScope.Chapter)
                    {
                        // there are no repeated chapters so there is no chapter_previous_chapter_numbers to clear

                        verse_previous_verse_numbers.Clear();
                        verse_previous_chapter_numbers.Clear();

                        word_previous_word_numbers.Clear();
                        word_previous_verse_numbers.Clear();
                        word_previous_chapter_numbers.Clear();

                        letter_previous_letter_numbers.Clear();
                        letter_previous_word_numbers.Clear();
                        letter_previous_verse_numbers.Clear();
                        letter_previous_chapter_numbers.Clear();
                    }

                    foreach (Verse verse in chapter.Verses)
                    {
                        string verse_text = verse.Text;
                        if (!verse_previous_verse_numbers.ContainsKey(verse_text))
                        {
                            verse.DistanceToPrevious.dL = -1; // non-applicable
                            verse.DistanceToPrevious.dW = -1; // non-applicable
                            verse.DistanceToPrevious.dV = 0;
                            verse.DistanceToPrevious.dC = 0;

                            verse_previous_verse_numbers.Add(verse_text, verse.Number);
                            verse_previous_chapter_numbers.Add(verse_text, verse.Chapter.Number);
                        }
//.........這裏部分代碼省略.........
開發者ID:ATouhou,項目名稱:QuranCode,代碼行數:101,代碼來源:Book.cs


注:本文中的Model.Dictionary.Clear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。