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


C# ArrayList.LastIndexOf方法代码示例

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


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

示例1: TestLastIndexOfBasic

        public void TestLastIndexOfBasic()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            int ndx = -1;
            //
            //  Construct array lists.
            //
            arrList = new ArrayList((ICollection)strHeroes);

            //
            // []  Obtain last index of "Batman" items.
            //
            ndx = arrList.LastIndexOf("Batman");
            if (ndx != -1)
            {
                Assert.Equal(0, strHeroes[ndx].CompareTo((string)arrList[ndx]));
            }

            //
            // []  Attempt to find null object.
            //
            // Remove range of items.
            ndx = arrList.LastIndexOf(null);
            Assert.Equal(-1, ndx);

            // []  Call LastIndexOf on an empty list
            var myList = new ArrayList();
            var lastIndex = myList.LastIndexOf(6);

            Assert.Equal(-1, lastIndex);
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:34,代码来源:LastIndexOfTests.cs

示例2: ArticleInfo


//.........这里部分代码省略.........
                    lbAlerts.Items.Add("Multiple DEFAULTSORTs found");

                // https://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests/Archive_5#Some_additional_edits
                deadLinks = TheArticle.DeadLinks();
                if (deadLinks.Count > 0)
                    lbAlerts.Items.Add("Dead links found" + " (" + deadLinks.Count + ")");

                ambigCiteDates = TheArticle.AmbiguousCiteTemplateDates();
                if (ambigCiteDates.Count > 0)
                    lbAlerts.Items.Add("Ambiguous citation dates found" + " (" + ambigCiteDates.Count + ")");

                unbalancedBracket = TheArticle.UnbalancedBrackets();
                if (unbalancedBracket.Count > 0)
                    lbAlerts.Items.Add("Unbalanced brackets found" + " (" + unbalancedBracket.Count + ")");

                badCiteParameters = TheArticle.BadCiteParameters();
                if (badCiteParameters.Count > 0)
                    lbAlerts.Items.Add("Invalid citation parameter(s) found" + " (" + badCiteParameters.Count + ")");

                dupeBanerShellParameters = TheArticle.DuplicateWikiProjectBannerShellParameters();
                if (dupeBanerShellParameters.Count > 0)
                    lbAlerts.Items.Add("Duplicate parameter(s) found in WPBannerShell" + " (" + dupeBanerShellParameters.Count + ")");

                UnknownWikiProjectBannerShellParameters = TheArticle.UnknownWikiProjectBannerShellParameters();
                if (UnknownWikiProjectBannerShellParameters.Count > 0)
                {
                    string warn = "Unknown parameters in WPBannerShell: " + " (" + UnknownWikiProjectBannerShellParameters.Count + ") ";
                    foreach (string s in UnknownWikiProjectBannerShellParameters)
                        warn += s + ", ";
                    lbAlerts.Items.Add(warn);
                }

                UnknownMultipleIssuesParameters = TheArticle.UnknownMultipleIssuesParameters();
                if (UnknownMultipleIssuesParameters.Count > 0)
                {
                    string warn = "Unknown parameters in Multiple issues: " + " (" + UnknownMultipleIssuesParameters.Count + ") ";
                    foreach (string s in UnknownMultipleIssuesParameters)
                        warn += s + ", ";
                    lbAlerts.Items.Add(warn);
                }

                unclosedTags = TheArticle.UnclosedTags();
                if (unclosedTags.Count > 0)
                    lbAlerts.Items.Add("Unclosed tag(s) found" + " (" + unclosedTags.Count + ")");

                if (TheArticle.HasSeeAlsoAfterNotesReferencesOrExternalLinks)
                    lbAlerts.Items.Add("See also section out of place");

                // check for {{sic}} tags etc. when doing typo fixes
                if (chkRegExTypo.Checked && TheArticle.HasSicTag)
                    lbAlerts.Items.Add(@"Page contains 'sic' tag/template");

                lblWords.Text = Words + wordCount;
                lblCats.Text = Cats + catCount;
                lblImages.Text = Imgs + WikiRegexes.Images.Matches(articleText).Count;
                lblLinks.Text = Links + WikiRegexes.WikiLinksOnly.Matches(articleText).Count;
                lblInterLinks.Text = IWLinks + Tools.InterwikiCount(articleText);

                // for date types count ignore images and URLs
                string articleTextNoImagesURLs = WikiRegexes.Images.Replace(WikiRegexes.ExternalLinks.Replace(articleText, ""), "");
                lblDates.Text = Dates + WikiRegexes.ISODates.Matches(articleTextNoImagesURLs).Count + "/" + WikiRegexes.DayMonth.Matches(articleTextNoImagesURLs).Count
                    + "/" + WikiRegexes.MonthDay.Matches(articleTextNoImagesURLs).Count;

                // Find multiple links
                ArrayList arrayLinks = new ArrayList();
                ArrayList arrayLinks2 = new ArrayList();

                //get all the links, ignore commented out text etc.
                foreach (Match m in WikiRegexes.WikiLink.Matches(Tools.ReplaceWithSpaces(articleText, WikiRegexes.UnformattedText.Matches(articleText))))
                {
                    string x = m.Groups[1].Value;
                    if (!WikiRegexes.Dates.IsMatch(x) && !WikiRegexes.Dates2.IsMatch(x))
                        // https://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Multiple_links
                        // make first character uppercase so that [[proton]] and [[Proton]] are marked as duplicate
                        x = Tools.TurnFirstToUpper(x);
                    arrayLinks.Add(x);
                }

                lbDuplicateWikilinks.Sorted = true;

                //add the duplicate articles to the listbox
                lbDuplicateWikilinks.BeginUpdate();
                foreach (string z in arrayLinks)
                {
                    if ((arrayLinks.IndexOf(z) < arrayLinks.LastIndexOf(z)) && (!arrayLinks2.Contains(z)))
                    {
                        arrayLinks2.Add(z);
                        // include count of links in form Proton (3)
                        int linkcount = Regex.Matches(articleText, @"\[\[" + Regex.Escape(z) + @"(\|.*?)?\]\]").Count;

                        if (!Tools.TurnFirstToLower(z).Equals(z))
                            linkcount += Regex.Matches(articleText, @"\[\[" + Regex.Escape(Tools.TurnFirstToLower(z)) + @"(\|.*?)?\]\]").Count;

                        lbDuplicateWikilinks.Items.Add(z + @" (" + linkcount + @")");
                    }
                }
                lbDuplicateWikilinks.EndUpdate();
            }
            lblDuplicateWikilinks.Visible = lbDuplicateWikilinks.Visible = btnRemove.Visible = (lbDuplicateWikilinks.Items.Count > 0);
        }
开发者ID:svn2github,项目名称:autowikibrowser,代码行数:101,代码来源:Main.cs

示例3: ArticleInfo

        private void ArticleInfo(bool reset)
        {
            lblWarn.Text = "";
            lbDuplicateWikilinks.Items.Clear();

            if (reset)
            {
                //Resets all the alerts.
                lblWords.Text = "Words: ";
                lblCats.Text = "Categories: ";
                lblImages.Text = "Images: ";
                lblLinks.Text = "Links: ";
                lblInterLinks.Text = "Interwiki links: ";
            }
            else
            {
                string articleText = txtEdit.Text;

                int intWords = Tools.WordCount(articleText);
                int intCats = WikiRegexes.Category.Matches(articleText).Count;
                int intImages = WikiRegexes.Images.Matches(articleText).Count;
                int intInterLinks = Tools.InterwikiCount(articleText);
                int intLinks = WikiRegexes.WikiLinksOnly.Matches(articleText).Count;

                intLinks = intLinks - intInterLinks - intImages - intCats;

                if (TheArticle.NameSpaceKey == 0 && (WikiRegexes.Stub.IsMatch(articleText)) && (intWords > 500))
                    lblWarn.Text = "Long article with a stub tag.\r\n";

                if (!(Regex.IsMatch(articleText, "\\[\\[" + Variables.Namespaces[Namespace.Category],
                    RegexOptions.IgnoreCase)))
                {
                    lblWarn.Text += "No category (although one may be in a template)\r\n";
                }

                // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Replace_nofootnotes_with_morefootnote_if_references_exists
                if (TheArticle.HasMorefootnotesAndManyReferences)
                    lblWarn.Text += @"Has 'No/More footnotes' template yet many references" + "\r\n";

                // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#.28Yet.29_more_reference_related_changes.
                if (TheArticle.HasRefAfterReflist)
                    lblWarn.Text += @"Has a <ref> after <references/>" + "\r\n";

                if (articleText.StartsWith("=="))
                    lblWarn.Text += "Starts with heading.";

                // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Format_references
                if(TheArticle.HasBareReferences)
                    lblWarn.Text += @"Unformatted references found" + "\r\n";

                lblWords.Text = "Words: " + intWords;
                lblCats.Text = "Categories: " + intCats;
                lblImages.Text = "Images: " + intImages;
                lblLinks.Text = "Links: " + intLinks;
                lblInterLinks.Text = "Interwiki links: " + intInterLinks;

                //Find multiple links                
                ArrayList arrayLinks = new ArrayList();
                ArrayList arrayLinks2 = new ArrayList();

                //get all the links
                foreach (Match m in WikiRegexes.WikiLink.Matches(articleText))
                {
                    string x = m.Groups[1].Value;
                    if (!WikiRegexes.Dates.IsMatch(x) && !WikiRegexes.Dates2.IsMatch(x))
                        // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Multiple_links
                        // make first character uppercase so that [[proton]] and [[Proton]] are marked as duplicate
                        x = Tools.TurnFirstToUpper(x);
                        arrayLinks.Add(x);
                }

                lbDuplicateWikilinks.Sorted = true;

                //add the duplicate articles to the listbox
                foreach (string z in arrayLinks)
                {
                    if ((arrayLinks.IndexOf(z) < arrayLinks.LastIndexOf(z)) && (!arrayLinks2.Contains(z)))
                    {
                        arrayLinks2.Add(z);
                        // include count of links in form Proton (3)
                        lbDuplicateWikilinks.Items.Add(z + @" (" + (Regex.Matches(articleText, @"\[\[" + Regex.Escape(z) + @"(\|.*?)?\]\]").Count + Regex.Matches(articleText, @"\[\[" + Regex.Escape(Tools.TurnFirstToLower(z)) + @"(\|.*?)?\]\]").Count) + @")");
                    }
                }
            }
            lblDuplicateWikilinks.Visible = lbDuplicateWikilinks.Visible = btnRemove.Visible = (lbDuplicateWikilinks.Items.Count > 0);
        }
开发者ID:svn2github,项目名称:autowikibrowser,代码行数:86,代码来源:Main.cs

示例4: ArticleInfo


//.........这里部分代码省略.........
                if (TheArticle.NameSpaceKey == Namespace.Article && WikiRegexes.Stub.IsMatch(articleText) &&
                    wordCount > 500)
                    warnings.AppendLine("Long article with a stub tag.");

                if (catCount == 0 && !Namespace.IsTalk(TheArticle.Name))
                    warnings.AppendLine("No category (may be one in a template)");

                // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Replace_nofootnotes_with_morefootnote_if_references_exists
                if (TheArticle.HasMorefootnotesAndManyReferences)
                    warnings.AppendLine("Has 'No/More footnotes' template yet many references");

                // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#.28Yet.29_more_reference_related_changes.
                if (TheArticle.HasRefAfterReflist)
                    warnings.AppendLine(@"Has a <ref> after <references/>");
                
                if(TheArticle.IsDisambiguationPageWithRefs)
                    warnings.AppendLine(@"DAB page with <ref>s");

                if (articleText.StartsWith("=="))
                    warnings.AppendLine("Starts with heading");

                // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Format_references
                if (TheArticle.HasBareReferences)
                    warnings.AppendLine("Unformatted references found");

                // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Detect_multiple_DEFAULTSORT
                if (WikiRegexes.Defaultsort.Matches(txtEdit.Text).Count > 1)
                    warnings.AppendLine("Multiple DEFAULTSORTs found");

                // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Some_additional_edits
                deadLinks = TheArticle.DeadLinks();
                if (deadLinks.Count > 0)
                    warnings.AppendLine("Dead links found");

                ambigCiteDates = TheArticle.AmbiguousCiteTemplateDates();
                if (ambigCiteDates.Count > 0)
                    warnings.AppendLine("Ambiguous citation dates found");

                _unbalancedBracket = TheArticle.UnbalancedBrackets(ref _bracketLength);
                if (_unbalancedBracket > -1)
                    warnings.AppendLine("Unbalanced brackets found");

                badCiteParameters = TheArticle.BadCiteParameters();
                if (badCiteParameters.Count > 0)
                    warnings.AppendLine("Invalid citation parameter(s) found");
                
                unclosedTags = TheArticle.UnclosedTags();
                if (unclosedTags.Count > 0)
                    warnings.AppendLine("Unclosed tag(s) found");

                lblWords.Text = Words + wordCount;
                lblCats.Text = Cats + catCount;
                lblImages.Text = Imgs + WikiRegexes.Images.Matches(articleText).Count;
                lblLinks.Text = Links + WikiRegexes.WikiLinksOnly.Matches(articleText).Count;
                lblInterLinks.Text = IWLinks + Tools.InterwikiCount(articleText);
                
                // for date types count ignore images and URLs
                string articleTextNoImagesURLs = WikiRegexes.Images.Replace(WikiRegexes.ExternalLinks.Replace(articleText, ""), "");
                lblDates.Text = Dates + WikiRegexes.ISODates.Matches(articleTextNoImagesURLs).Count + "/" + WikiRegexes.DayMonth.Matches(articleTextNoImagesURLs).Count
                    + "/" + WikiRegexes.MonthDay.Matches(articleTextNoImagesURLs).Count;
                
                lblWarn.Text = warnings.ToString();

                // Find multiple links
                ArrayList arrayLinks = new ArrayList();
                ArrayList arrayLinks2 = new ArrayList();

                //get all the links
                foreach (Match m in WikiRegexes.WikiLink.Matches(articleText))
                {
                    string x = m.Groups[1].Value;
                    if (!WikiRegexes.Dates.IsMatch(x) && !WikiRegexes.Dates2.IsMatch(x))
                        // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Multiple_links
                        // make first character uppercase so that [[proton]] and [[Proton]] are marked as duplicate
                        x = Tools.TurnFirstToUpper(x);
                    arrayLinks.Add(x);
                }

                lbDuplicateWikilinks.Sorted = true;

                //add the duplicate articles to the listbox
                lbDuplicateWikilinks.BeginUpdate();
                foreach (string z in arrayLinks)
                {
                    if ((arrayLinks.IndexOf(z) < arrayLinks.LastIndexOf(z)) && (!arrayLinks2.Contains(z)))
                    {
                        arrayLinks2.Add(z);
                        // include count of links in form Proton (3)
                        lbDuplicateWikilinks.Items.Add(z + @" (" +
                                                       (Regex.Matches(articleText,
                                                                      @"\[\[" + Regex.Escape(z) + @"(\|.*?)?\]\]").Count +
                                                        Regex.Matches(articleText,
                                                                      @"\[\[" + Regex.Escape(Tools.TurnFirstToLower(z)) +
                                                                      @"(\|.*?)?\]\]").Count) + @")");
                    }
                }
                lbDuplicateWikilinks.EndUpdate();
            }
            lblDuplicateWikilinks.Visible = lbDuplicateWikilinks.Visible = btnRemove.Visible = (lbDuplicateWikilinks.Items.Count > 0);
        }
开发者ID:svn2github,项目名称:autowikibrowser,代码行数:101,代码来源:Main.cs

示例5: LastIndexOf_CountOverflow

		public void LastIndexOf_CountOverflow ()
		{
			ArrayList al = new ArrayList ();
			al.Add (this);
			al.LastIndexOf ('a', 1, Int32.MaxValue);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:6,代码来源:ArrayListTest.cs

示例6: LastIndexOf_StartIndexOverflow

		public void LastIndexOf_StartIndexOverflow ()
		{
			ArrayList al = new ArrayList ();
			al.Add (this);
			al.LastIndexOf ('a', Int32.MaxValue, 1);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:6,代码来源:ArrayListTest.cs

示例7: TestLastIndexOf

		public void TestLastIndexOf ()
		{
			//{
			//bool errorThrown = false;
			//try {
			//ArrayList a = new ArrayList(1);
			//int i = a.LastIndexOf('a', -1);
			//} catch (ArgumentOutOfRangeException) {
			//errorThrown = true;
			//}
			//Assert.IsTrue (//errorThrown, "first negative lastindexof error not thrown");
			//}
			{
				bool errorThrown = false;
				try {
					ArrayList a = new ArrayList (1);
					int i = a.LastIndexOf ('a', 2);
				} catch (ArgumentOutOfRangeException) {
					errorThrown = true;
				}
				Assert.IsTrue (errorThrown, "past-end lastindexof error not thrown");
			}
			//{
			//bool errorThrown = false;
			//try {
			//ArrayList a = new ArrayList(1);
			//int i = a.LastIndexOf('a', 0, -1);
			//} catch (ArgumentOutOfRangeException) {
			//errorThrown = true;
			//}
			//Assert.IsTrue (//errorThrown, "second negative lastindexof error not thrown");
			//}
			//{
			//bool errorThrown = false;
			//try {
			//ArrayList a = new ArrayList(1);
			//int i = a.LastIndexOf('a', 0, 2);
			//} catch (ArgumentOutOfRangeException) {
			//errorThrown = true;
			//}
			//Assert.IsTrue (//errorThrown, "past-end lastindexof error not thrown");
			//}
			//{
			//bool errorThrown = false;
			//try {
			//ArrayList a = new ArrayList(2);
			//int i = a.LastIndexOf('a', 0, 2);
			//} catch (ArgumentOutOfRangeException) {
			//errorThrown = true;
			//}
			//Assert.IsTrue (//errorThrown, "past-end lastindexof error not thrown");
			//}
			int iTest = 0;
			try {
				char [] c = { 'a', 'b', 'c', 'd', 'e' };
				ArrayList a = new ArrayList (c);
				Assert.AreEqual (-1, a.LastIndexOf (null), "never find null");
				iTest++;
				Assert.AreEqual (-1, a.LastIndexOf (null, 4), "never find null");
				iTest++;
				Assert.AreEqual (-1, a.LastIndexOf (null, 4, 5), "never find null");
				iTest++;
				Assert.AreEqual (2, a.LastIndexOf ('c'), "can't find elem");
				iTest++;
				Assert.AreEqual (2, a.LastIndexOf ('c', 4), "can't find elem");
				iTest++;
				Assert.AreEqual (2, a.LastIndexOf ('c', 3, 2), "can't find elem");
				iTest++;
				Assert.AreEqual (-1, a.LastIndexOf ('c', 4, 2), "shouldn't find elem");
				iTest++;
				Assert.AreEqual (-1, a.LastIndexOf ('?'), "shouldn't find");
				iTest++;
				Assert.AreEqual (-1, a.LastIndexOf (1), "shouldn't find");
			} catch (Exception e) {
				Assert.Fail ("Unexpected exception caught when iTest=" + iTest + ". e=" + e);
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:77,代码来源:ArrayListTest.cs

示例8: ArticleInfo

        private void ArticleInfo(bool reset)
        {
            string articleText = txtEdit.Text;
            int intWords = 0;
            int intCats = 0;
            int intImages = 0;
            int intLinks = 0;
            int intInterLinks = 0;
            lblWarn.Text = "";
            lbDuplicateWikilinks.Items.Clear();

            if (reset)
            {
                //Resets all the alerts.
                lblWords.Text = "Words: ";
                lblCats.Text = "Categories: ";
                lblImages.Text = "Images: ";
                lblLinks.Text = "Links: ";
                lblInterLinks.Text = "Interwiki links: ";

                lblDuplicateWikilinks.Visible = false;
                lbDuplicateWikilinks.Visible = false;
                btnRemove.Visible = false;
            }
            else
            {
                intWords = Tools.WordCount(articleText);

                intCats = Regex.Matches(articleText, "\\[\\[" + Variables.Namespaces[14], RegexOptions.IgnoreCase).Count;

                intImages = Regex.Matches(articleText, "\\[\\[" + Variables.Namespaces[6], RegexOptions.IgnoreCase).Count;

                intInterLinks = Tools.InterwikiCount(articleText);

                intLinks = WikiRegexes.WikiLinksOnly.Matches(articleText).Count;

                intLinks = intLinks - intInterLinks - intImages - intCats;

                if (TheArticle.NameSpaceKey == 0 && (WikiRegexes.Stub.IsMatch(articleText)) && (intWords > 500))
                    lblWarn.Text = "Long article with a stub tag.\r\n";

                if (!(Regex.IsMatch(articleText, "\\[\\[" + Variables.Namespaces[14], RegexOptions.IgnoreCase)))
                    lblWarn.Text += "No category (although one may be in a template)\r\n";

                if (articleText.StartsWith("=="))
                    lblWarn.Text += "Starts with heading.";

                lblWords.Text = "Words: " + intWords.ToString();
                lblCats.Text = "Categories: " + intCats.ToString();
                lblImages.Text = "Images: " + intImages.ToString();
                lblLinks.Text = "Links: " + intLinks.ToString();
                lblInterLinks.Text = "Interwiki links: " + intInterLinks.ToString();

                //Find multiple links                
                ArrayList arrayLinks = new ArrayList();
                string x = "";
                //get all the links
                foreach (Match m in WikiRegexes.WikiLink.Matches(articleText))
                {
                    x = m.Groups[1].Value;
                    if (!WikiRegexes.Dates.IsMatch(x) && !WikiRegexes.Dates2.IsMatch(x))
                        arrayLinks.Add(x);
                }

                lbDuplicateWikilinks.Sorted = true;

                //add the duplicate articles to the listbox
                foreach (string z in arrayLinks)
                {
                    if ((arrayLinks.IndexOf(z) < arrayLinks.LastIndexOf(z)) && (!lbDuplicateWikilinks.Items.Contains(z)))
                        lbDuplicateWikilinks.Items.Add(z);
                }
                arrayLinks = null;

                if (lbDuplicateWikilinks.Items.Count > 0)
                {
                    lblDuplicateWikilinks.Visible = true;
                    lbDuplicateWikilinks.Visible = true;
                    btnRemove.Visible = true;
                }
            }
        }
开发者ID:svn2github,项目名称:autowikibrowser,代码行数:82,代码来源:Main.cs

示例9: PrivateTestIndexOf

		private void PrivateTestIndexOf(ArrayList arrayList) 
		{
			int x;
			
			arrayList.AddRange(c_TestData);

			for (int i = 0; i < 10; i++) 
			{			
				x = arrayList.IndexOf(i);
				Assert.IsTrue(x == i, "ArrayList.IndexOf(" + i + ")");
			}

			try 
			{
				arrayList.IndexOf(0, 10, 1);
				Assert.Fail("ArrayList.IndexOf(0, 10, 1)");
			}
			catch (ArgumentOutOfRangeException) 
			{
			}

			try 
			{
				arrayList.IndexOf(0, 0, -1);
				Assert.Fail("ArrayList.IndexOf(0, 10, 1)");
			}
			catch (ArgumentOutOfRangeException) 
			{
			}

			try 
			{
				arrayList.IndexOf(0, -1, -1);
				Assert.Fail("ArrayList.IndexOf(0, 10, 1)");
			}
			catch (ArgumentOutOfRangeException) 
			{
			}

			try 
			{
				arrayList.IndexOf(0, 9, 10);				
				Assert.Fail("ArrayList.IndexOf(0, 10, 1)");
			}
			catch (ArgumentOutOfRangeException) 
			{				
			}

			try 
			{
				arrayList.IndexOf(0, 0, 10);				
			}
			catch (ArgumentOutOfRangeException) 
			{
				Assert.Fail("ArrayList.IndexOf(0, 10, 1)");
			}

			try 
			{
				arrayList.IndexOf(0, 0, 11);
				Assert.Fail("ArrayList.IndexOf(0, 10, 1)");
			}
			catch (ArgumentOutOfRangeException) 
			{				
			}

			// LastIndexOf

			for (int i = 0; i < 10; i++) 
			{
				x = arrayList.LastIndexOf(i);

				Assert.IsTrue(x == i, "ArrayList.LastIndexOf(" + i + ")");
			}			

			try 
			{
				arrayList.IndexOf(0, 10, 1);

				Assert.Fail("ArrayList.LastIndexOf(0, 10, 1)");
			}
			catch (ArgumentOutOfRangeException) 
			{
			}

			try 
			{
				arrayList.IndexOf(0, 0, -1);

				Assert.Fail("ArrayList.LastIndexOf(0, 10, 1)");
			}
			catch (ArgumentOutOfRangeException) 
			{
			}

			try 
			{
				arrayList.LastIndexOf(0, -1, -1);

				Assert.Fail("ArrayList.LastIndexOf(0, 10, 1)");
//.........这里部分代码省略.........
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:101,代码来源:NewArrayListTest.cs

示例10: TestInvalidIndex

        public void TestInvalidIndex()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            int ndx = -1;

            //
            // Construct array lists.
            //
            arrList = new ArrayList((ICollection)strHeroes);

            //
            // []  Obtain last index of "Batman" items.
            //
            ndx = arrList.Count;
            while ((ndx = arrList.LastIndexOf("Batman", --ndx)) != -1)
            {
                Assert.Equal(0, strHeroes[ndx].CompareTo((string)arrList[ndx]));
            }

            //
            // []  Attempt to find null object.
            //
            // Remove range of items.
            ndx = arrList.LastIndexOf(null, arrList.Count - 1);
            Assert.Equal(-1, ndx);

            //
            //  []  Attempt invalid LastIndexOf using negative endindex
            //
            Assert.Throws<ArgumentOutOfRangeException>(() => arrList.LastIndexOf("Batman", -1));

            //
            //  []  Attempt invalid LastIndexOf using negative startindex
            //
            Assert.Throws<ArgumentOutOfRangeException>(() => arrList.LastIndexOf("Batman", -1000));
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:39,代码来源:LastIndexOfTests.cs

示例11: TestArrayListWrappers

        public void TestArrayListWrappers()
        {
            //--------------------------------------------------------------------------
            // Variable definitions.
            //--------------------------------------------------------------------------
            ArrayList arrList = null;
            int ndx = -1;

            string[] strHeroes =
            {
                "Aquaman",
                "Atom",
                "Batman",
                "Black Canary",
                "Captain America",
                "Captain Atom",
                "Batman",
                "Catwoman",
                "Cyborg",
                "Flash",
                "Green Arrow",
                "Batman",
                "Green Lantern",
                "Hawkman",
                "Huntress",
                "Ironman",
                "Nightwing",
                "Batman",
                "Robin",
                "SpiderMan",
                "Steel",
                "Superman",
                "Thor",
                "Batman",
                "Wildcat",
                "Wonder Woman",
                "Batman",
                null
            };

            //
            // Construct array lists.
            //
            arrList = new ArrayList((ICollection)strHeroes);

            //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of 
            //BinarySearch, Following variable cotains each one of these types of array lists

            ArrayList[] arrayListTypes = {
                                    (ArrayList)arrList.Clone(),
                                    (ArrayList)ArrayList.Adapter(arrList).Clone(),
                                    (ArrayList)ArrayList.FixedSize(arrList).Clone(),
                                    (ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
                                    (ArrayList)ArrayList.ReadOnly(arrList).Clone(),
                                    (ArrayList)ArrayList.Synchronized(arrList).Clone()};

            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;

                //
                // []  Obtain last index of "Batman" items.
                //
                int startIndex = arrList.Count - 1;
                int tmpNdx = 0;
                while (0 < startIndex && (ndx = arrList.LastIndexOf("Batman", startIndex, startIndex + 1)) != -1)
                {
                    Assert.True(ndx <= startIndex);

                    Assert.Equal(0, strHeroes[ndx].CompareTo((string)arrList[ndx]));

                    tmpNdx = arrList.LastIndexOf("Batman", startIndex, startIndex - ndx + 1);
                    Assert.Equal(ndx, tmpNdx);

                    tmpNdx = arrList.LastIndexOf("Batman", startIndex, startIndex - ndx);
                    Assert.Equal(-1, tmpNdx);

                    startIndex = ndx - 1;
                }

                //
                // []  Attempt to find null object.
                //
                // Remove range of items.
                ndx = arrList.LastIndexOf(null, arrList.Count - 1, arrList.Count);
                Assert.NotEqual(-1, ndx);
                Assert.Null(arrList[ndx]);

                //
                //  []  Attempt invalid LastIndexOf using negative endindex
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.LastIndexOf("Batman", arrList.Count - 1, -1000));

                //
                //  []  Attempt invalid LastIndexOf using negative startindex
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.LastIndexOf("Batman", -1000, 0));

                //
                //  []  Attempt invalid LastIndexOf using endIndex greater than the size.
//.........这里部分代码省略.........
开发者ID:johnhhm,项目名称:corefx,代码行数:101,代码来源:LastIndexOfTests.cs

示例12: ArticleInfo

        private void ArticleInfo(bool reset)
        {
            lblWarn.Text = "";
            lbDuplicateWikilinks.Items.Clear();

            if (reset)
            {
                //Resets all the alerts.
                lblWords.Text = "Words: ";
                lblCats.Text = "Categories: ";
                lblImages.Text = "Images: ";
                lblLinks.Text = "Links: ";
                lblInterLinks.Text = "Interwiki links: ";
            }
            else
            {
                string articleText = txtEdit.Text;

                int intWords = Tools.WordCount(articleText);
                int intCats = WikiRegexes.Category.Matches(articleText).Count;
                int intImages = WikiRegexes.Images.Matches(articleText).Count;
                int intInterLinks = Tools.InterwikiCount(articleText);
                int intLinks = WikiRegexes.WikiLinksOnly.Matches(articleText).Count;

                intLinks = intLinks - intInterLinks - intImages - intCats;

                if (TheArticle.NameSpaceKey == 0 && (WikiRegexes.Stub.IsMatch(articleText)) && (intWords > 500))
                    lblWarn.Text = "Long article with a stub tag.\r\n";

                if (!(Regex.IsMatch(articleText, "\\[\\[" + Variables.Namespaces[Namespace.Category],
                    RegexOptions.IgnoreCase)))
                {
                    lblWarn.Text += "No category (although one may be in a template)\r\n";
                }

                // http://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Replace_nofootnotes_with_morefootnote_if_references_exists
                if (TheArticle.HasMorefootnotesAndManyReferences)
                    lblWarn.Text += @"Has 'No/More footnotes' template yet many references\r\n";

                if (articleText.StartsWith("=="))
                    lblWarn.Text += "Starts with heading.";

                lblWords.Text = "Words: " + intWords;
                lblCats.Text = "Categories: " + intCats;
                lblImages.Text = "Images: " + intImages;
                lblLinks.Text = "Links: " + intLinks;
                lblInterLinks.Text = "Interwiki links: " + intInterLinks;

                //Find multiple links                
                ArrayList arrayLinks = new ArrayList();

                //get all the links
                foreach (Match m in WikiRegexes.WikiLink.Matches(articleText))
                {
                    string x = m.Groups[1].Value;
                    if (!WikiRegexes.Dates.IsMatch(x) && !WikiRegexes.Dates2.IsMatch(x))
                        arrayLinks.Add(x);
                }

                lbDuplicateWikilinks.Sorted = true;

                //add the duplicate articles to the listbox
                foreach (string z in arrayLinks)
                {
                    if ((arrayLinks.IndexOf(z) < arrayLinks.LastIndexOf(z)) && (!lbDuplicateWikilinks.Items.Contains(z)))
                        lbDuplicateWikilinks.Items.Add(z);
                }
            }
            lblDuplicateWikilinks.Visible = lbDuplicateWikilinks.Visible = btnRemove.Visible = (lbDuplicateWikilinks.Items.Count > 0);
        }
开发者ID:svn2github,项目名称:autowikibrowser,代码行数:70,代码来源:Main.cs


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