Array.IndexOf(), Array.LastIndexOf() (C#) : Array « Collections « ASP.Net






Array.IndexOf(), Array.LastIndexOf() (C#)

<%@Page Language="c#" %>
<script runat="server" Language="c#">
  void Page_Load() 
  {
    int intCounter = -1;
    string[] AnimalArray = new string[5]
                {  "Dog", "Cat", "Elephant", "Lion", "Cat"};
    do
    {
      intCounter = Array.IndexOf(AnimalArray, "Cat", intCounter+1);
      MyText.InnerHtml += "AnimalArray[" + intCounter + "]<br/>";
    } while (intCounter != Array.LastIndexOf(AnimalArray, "Cat")); 
  }
</script>
<html>
  The string "Cat" occurs in the following elements:
  <br/>
  <div id="MyText" runat="server" />
</html>

           
       








Related examples in the same category

1.Array Reverse Demo (VB.net)
2.For Each loop through an Array (VB.net)
3.Array.IndexOf and Array.LastIndexOf (VB.net)
4.Get array by index (VB.net)
5.Sort an Array (VB.net)
6.For each loop: array (VB.net)
7.Change array length (VB.net)
8.Define and use array (VB.net)
9.Sort array reversely (C#)
10.Get array element by index (C#)
11.Use String Array to store Asp Label Text (C#)
12.Use Two dimensional array (C#)
13.Use array: find item index (C#)