c# indexer
What is Indexer ?
An indexer is a member that enables an object to be indexed in the same way as an array.
mark.cs
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.WebControls.WebParts;
using System.Web.UI.HtmlControls;
///
/// Summary description for mark
///
public class mark
{
public mark()
{
//
// TODO: Add constructor logic here
//
}
private string[] x = new string[5];
public string this [int index]
{
get
{
return x[index];
}
set
{
x[index] = value;
}
}
}
Execute in page load event in the page
protected void Page_Load(object sender, EventArgs e)
{
mark m = new mark();
m[0] = "kasun";
m[1] = "kasunt";
m[2] = "kasunl";
m[3] = "kasun1";
m[4] = "kasun2";
Response.Write(m[4]);
}
0 Response to "c# indexer"
Post a Comment