Sponsored Ad

Tuesday, May 4, 2010

How to Find Position of a Element in a Array

This post will help you to find the exact position of a element in given array. This program usage IndexOf method to find the element. Its returns –1 in case of a given element is not present in Array otherwise can return a index from 0 to array length-1.

 

How to Find Position of a Element in a Array

 

Source Code:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("If IndexOf methosd return -1, it means the content is not present in array <BR/><BR/>");
        string[] Sites = { "IndiHub.com", "TestingWiz.com", "SharePointBank.com" };
        int intLocation = Array.IndexOf(Sites, "IndiHub.com");
        Response.Write("Indihub.com Location is at: " + intLocation + "<BR/><BR/>");
         intLocation = Array.IndexOf(Sites, "BharatClick.com");
        Response.Write("BharatClick.com Location is at: " + intLocation + "<BR/><BR/>");
    }

}

0 comments:

Post a Comment

Sponsored Ad

More Related Articles

Website Update

Followers