Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Indexers in c#?

Answers were Sorted based on User's Feedback



Indexers in c#?..

Answer / supraja

C# introduces a new concept known as Indexers which are
used for treating an object as an array. The indexers are
usually known as smart arrays in C# community. Defining a
C# indexer is much like defining properties. We can say
that an indexer is a member that enables an object to be
indexed in the same way as an array.

The following is syntax

<modifier> <return type> this [argument list]
{
get
{
// Get codes goes here
}
set
{
// Set codes goes here
}
}

Is This Answer Correct ?    37 Yes 1 No

Indexers in c#?..

Answer / chaitanya.k

Indexers are used to retrieve the data faster than
retrieving the data from Arrays.

Is This Answer Correct ?    37 Yes 8 No

Indexers in c#?..

Answer / muhammad usman

Indexer is used to treat an object as an array

Is This Answer Correct ?    29 Yes 2 No

Indexers in c#?..

Answer / jignesh contractor

Indexer Concept is object act as an array.
Indexer an object to be indexed in the same way as an
array.
Indexer modifier can be private, public, protected or
internal.
The return type can be any valid C# types.
Indexers in C# must have at least one parameter. Else the
compiler will generate a compilation error.
this [Parameter]

{

get

{

// Get codes goes here

}

set

{

// Set codes goes here

}

}



For Example:



using System;

using System.Collections.Generic;

using System.Text;



namespace Indexers

{

class ParentClass

{

private string[] range = new string[5];

public string this[int indexrange]

{

get

{

return range[indexrange];

}

set

{

range[indexrange] = value;

}

}

}



/* The Above Class just act as array declaration using
this pointer */



class childclass

{

public static void Main()

{

ParentClass obj = new ParentClass();



/* The Above Class ParentClass create one
object name is obj */



obj[0] = "ONE";

obj[1] = "TWO";

obj[2] = "THREE";

obj[3] = "FOUR ";

obj[4] = "FIVE";

Console.WriteLine("WELCOME TO Jigs World\n");

Console.WriteLine("\n");



Console.WriteLine("{0}\n,{1}\n,{2}\n,{3}\n,{4}
\n", obj[0], obj[1], obj[2], obj[3], obj[4]);

Console.WriteLine("\n");

Console.WriteLine("Dont Fear Jigs is here\n");

Console.WriteLine("\n");

Console.ReadLine();

}

}

}

Is This Answer Correct ?    11 Yes 1 No

Indexers in c#?..

Answer / srinath thanuku

Sample code to use Indexers when there are more than one
variable in a Class.

class IndexerExample
{
private string[] SkillSet = new string[5];
private string userName;
private int salary;
public string this[int indexrange]
{
set
{
SkillSet[indexrange] = value;
}
get
{
return SkillSet[indexrange];
}
}
public int sal
{
get
{
return salary;
}
set
{
salary = value;
}
}
public string name
{
get
{
return userName;
}
set
{
userName = value;
}
}

}

Creating an Object of the Above Class:
IndexerExample obj = new IndexerExample();
obj[0] = "C#";
obj[1] = "VB.Net";
obj[2] = "ASP.Net";
obj[3] = "SQL Server 2005";
obj[4] = "JScript.Net";
obj.sal = 1000;
obj.name ="Madhavi K.";

Is This Answer Correct ?    14 Yes 4 No

Indexers in c#?..

Answer / dhara

indexer are the smart array in c# which retrive records
faster than simple array

Is This Answer Correct ?    9 Yes 1 No

Indexers in c#?..

Answer / srinivasu

1.Indexer is a concept of using an object like an array.
2.indexers are similar to properties
3.Indexer is a collection of SET and GET methods.
4.Indexer name must be "this".
5.One class can have only one indexer.

syntax:
------

properties:
-----------
string s;
public string Pname
{
set { s=value;}

get { return s;}
}


Indexers:(example)
---------

class test
{
string [] x=new string[3];
public string this [int i]
{
set {x[i]=value;}

get {return x[i];}

}

public void print()
{
for(int i=0;i<x.lenght;i++)
messageBox.show(x[i]);

}

}
//using

test t=new test();
t[0]="vasu";
t[1]="liki";
t[2]="kavi";
t.print();

Is This Answer Correct ?    16 Yes 11 No

Indexers in c#?..

Answer / rajkumar

hi..all you said in the above example is by considering
only 1 variable in a class i.e., string. if suppose i have
multiple variables/members in class how can use indexer
conscept.

i think u got my question. ur only assing 1 value through
object. what if i had other variables in class.??

please clarify my doubt. very urgent

Is This Answer Correct ?    4 Yes 3 No

Post New Answer

More C Sharp Interview Questions

Is char * null terminated?

0 Answers  


Trace the O/p for a program on inheritance and Polymorphism. 3 classes A,B,C A with two methods public virtual SomeMethodA public virtual SomemoreMethodA B:A overide SomeMethodA C:B new Method SomeMethodA override SomeMoreMethodA main method { b new instance of B b.SomeMethodA b.SomeMoreMethodA b1 new instance of C b1.SomeMethodA b1.SomeMoreMethodA }

2 Answers   Proteans,


3. Use layered architecture for coding. s.no name description 1 abc xxxxxxxxx 2 abc xxxxxxxxx 3 4 5 6 7 8 Select all Clear all Add Delete Name Description Save close

0 Answers  


Why are dynamic link library used over static one?

0 Answers   C DAC,


What is verbatim string?

0 Answers  


what is CSharp

6 Answers  


what is the lifespan of the items stored in viewstate ?

4 Answers  


What is object array in c#?

0 Answers  


What tool we have to use to install assembli in gac folder.

0 Answers  


What does char mean in c#?

0 Answers  


1. What is IIS. pl explain practically. 2. Difference b/w webserver and application server. pl explain practically.

1 Answers  


What is array? What are jagged array ?

1 Answers  


Categories