You must Sign In to post a response.
  • Category: ASP.NET

    Write a programme to find the index of an element from array in C#?

    write a programme to find the index of an element from array in C#?
  • #476006
    s.IndexOf("string");
    s.LastIndexOf("string");

    hope this help!

    thnx
    Muhil

  • #476024
    <%@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>

    Thanks&Regards
    DurgaPrasad

  • #476174
    string[] arr = new string[3] { "a", "b", "c" };
    for (int i = 0; i < arr.Length; i++)
    {
    if (arr[i] == "b")
    {
    int index = i;
    }
    }

    DNS MVM and .Net Guru
    Team Lead at CirrusCloud Systems
    Bhubaneswar,Odisha
    Thanks and Regards,
    Abhay Kumar Raut

  • #476396
    Reddy,

    Hope your issue resolved now

    Thanks & regards,
    Gaurav Kumar Arora
    Site Coordinator - DNS
    My blog - http://gaurav-arora.com


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.