how to access array element in unity3d in C#

hi,
i created an array for material and assign them in inspector panel, now i have to access the element which element is selected.

How to access that element?

Please help. Thanks

Here is my code for array.

using UnityEngine;
using System.Collections;

public class Raycast : MonoBehaviour 
{
	public Ray ray;
	public RaycastHit hit;
	public Texture2D[] diffuseTextures;
	public int indexPointer = 0;

	void Update()
	{
		ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		if(Physics.Raycast(ray, out hit))
		{
			
			if(Input.GetMouseButtonUp(0)){
				if(hit.transform.tag == "CubeTag"){
					hit.collider.gameObject.renderer.material.SetTexture("_MainTex", diffuseTextures[indexPointer]);
					indexPointer++;
					print (indexPointer);
					if (indexPointer >= diffuseTextures.Length) {
						indexPointer = 0;
					}
				}
			}
		}
	}
}

I believe what your looking for is a for loop.

 for(var i = 0; i < diffuseTextures.Length; i++)
    	{
    		//stuff to do
    	}

You’ve said that what you need is “to access the texture according to IndexPointer”. You can do that with this code: diffuseTextures[indexPointer]

I was using this for UVs animation, maybe it can help you but it’s in unityscript

//vars for the whole sheet
var colCount    : int =  4;
var rowCount    : int =  4;

//vars for animation
var rowNumber   : int =  0; //Zero Indexed
var colNumber   : int =  0; //Zero Indexed
var totalCells  : int =  4;
var fps  : int = 10;
private var offset  : Vector2;

//Update
function Update () { SetSpriteAnimation(colCount,rowCount,rowNumber,colNumber,totalCells,fps);  }

//SetSpriteAnimation
function SetSpriteAnimation(colCount : int,rowCount : int,rowNumber : int,colNumber : int,totalCells : int,fps : int){

    // Calculate index
    var index : int = Time.time * fps;
    // Repeat when exhausting all cells
    index = index % totalCells;
   
    // Size of every cell
    var size = Vector2 (1.0 / colCount, 1.0 / rowCount);
   
    // split into horizontal and vertical index
    var uIndex = index % colCount;
    var vIndex = index / colCount;
 
    // build offset
    // v coordinate is the bottom of the image in opengl so we need to invert.
    offset = Vector2 ((uIndex+colNumber) * size.x, (1.0 - size.y) - (vIndex+rowNumber) * size.y);
   
    renderer.material.SetTextureOffset ("_MainTex", offset);
    renderer.material.SetTextureScale  ("_MainTex", size);
}

You are not simply looking for Array.IndexOf() are you?