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...


What are properties and indexer?

Answers were Sorted based on User's Feedback



What are properties and indexer?..

Answer / soft.narayan@gmail.com

This answer posted by me soft.narayan@gmail.com,If u have
any query please let me know......

Using an object like an array is called Indexer.
Indexer is similar to properties.Indexer is a collection of
set and get procedures.Indexer name must be "this" only.
One class can have only one indexer.

Syntax to create Indexer:
string s
public string firstname
{
set{ s=value;}
get (return s;}
}

string[] x=new string[5];
public string this[inti]
{
set {x[i]=value}
get { return x[i]}
}
}

Is This Answer Correct ?    9 Yes 1 No

What are properties and indexer?..

Answer / priya

1. An index is identified by it's signature. But a property
is identified it's name.
2. An indexer is always an instance member, but a property
can be static also.
3. An indexer is accessed through an element access. But a
property is through a member access.

Is This Answer Correct ?    6 Yes 0 No

What are properties and indexer?..

Answer / uday

Properties are not like variables, rather they are calling
methods. They dont be allocated memory like variables.
They(get,set accessors) will be called automatically when
we assigne value or refer the value.
class ProperyCls
{
string name;
public string Name
{
get
{
return name;
}
set
{
Console.WriteLine("In Set method the value
is "+value);
name = value;
}
}
}

class Program
{
static void Main(string[] args)
{
ProperyCls pObj = new ProperyCls();

//Here the set method will be automatically
called
pObj.Name = "Hello";

//Here the get method will be called
automatically
Console.WriteLine("In get method the value is "
+ pObj.Name);

Console.ReadKey();

}
}

Indexers are different in the context when i create
multiple instances of the class and assign properties for
each of the instances. Indexers can be defined with "this"
keyword.
class ProperyCls
{

public int this[int i]
{
get
{
return 20;
}
set
{
Console.WriteLine("In set the value is " +
value + "at index" + i);
}
}
}


class Program
{
static void Main(string[] args)
{
ProperyCls pObj = new ProperyCls();

pObj[1] = 10;
pObj[2] = 30;

Console.WriteLine("In get method the value
returned is " + pObj[1]);
Console.ReadKey();

}
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

How does the clr work?

0 Answers  


Can a constructor be static in c#?

0 Answers  


Explain the Abstract class in c#.net

0 Answers  


can you overload a method of class A in Class B if it is derived class of A?If it is yes tell me how is it possible?

4 Answers   Mphasis, Ness Technologies,


Do while loops yes or no c#?

0 Answers  


How to find methods of a assembly file (not using ILDASM)?

0 Answers  


How can we sort an array in c#?

0 Answers  


why delegate is type safe?

0 Answers   IBS,


In gridview in editmode if we want to display information in one combobox based on

0 Answers   FD, Microsoft,


OOPs concept ?

1 Answers   iGate, MMTS,


What is difference between a type and class?

0 Answers   Arigo Infotech,


What is local function?

0 Answers  


Categories