class Mango
{
private int a;
public int A { get{return a;} set{a=value;} }
private string b;
public string B { get { return b; } set { b = value; } }
}
class Banana1
{
public Mango[] m = new Mango[8];
public Mango this[int index]
{
get { return m[index]; }
set { m[index] = value; }
}
public static void Main(string []args)
{
//Please Implement code here for Mango class obj which hold 2 data maeber
}
Can we access whole obj as indexer if yes , would it be as multidimensional array
Or for one datamember we have one indexer
}
VulpesPosted Jun 3, 2013, 8:29 AM
There are no restrictions on the return type of an indexer so you could return the whole array of Mango objects. However, it would make no sense to do so since an indexer has to have at least one parameter and this would just become a 'dummy' parameter with no use.
However, if 'm' were a two 2 dimensional rectangular array (or jagged array) of Mangos, then it would make sense for the indexer to return a one dimensional array of Mangos depending on the index passed in.