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

What is the difference between values and reference types?

0 Answers   Alcatel-Lucent,


What is Lambda Expression?

1 Answers  


how to store the value in textbox using delegates if we have two user control. the value will be called from one user control to another user control. Loading and unloading will be done through delegates.

1 Answers  


HOw to judge a person for a team if you are allowed to ask only 2 questions to him?

2 Answers   TCS,


can we assign null value to value type in c#?

12 Answers   Idea, Microsoft, Wipro,


In a memory when you Box and Unbox a value-type what happens?

0 Answers   Siebel,


What is enum in c#?

0 Answers  


What are the basics of c#?

0 Answers  


What is private protected in c#?

0 Answers  


Explain ACID rule of thumb for transactions.

1 Answers  


Difference between a sub and a function in c#.

0 Answers  


Hi to all..I have to create an intranet application on C#.NET windows Application so please please let can you people help me as iam new in .NET and if u have any samples or website address from where i can get sample please let know.

0 Answers   ABB, TCS,


Categories