set & get methods for Collections

  • Thread starter Thread starter Sadun Sevingen
  • Start date Start date
S

Sadun Sevingen

i have SqlParameterCollection and i want to reach it by SET and GET
methods...

public SqlParameterCollection Parameter this[string Parameter]
{
get
{
return Command.Parameters[Parameter];
}
set
{
Command.Parameters[Parameter] = value;
}
}

which is not right... but i want to do ???
 
Hi,

You have to write like this:

public SqlParameterCollection this[string Parameter]
{
get
{
return Command.Parameters[Parameter];
}
set
{
Command.Parameters[Parameter] = value;
}
}

Sridhar!!
 
but this give collection property to object... i want to access into an
collection in the object...

lets say... i have object A and it has C attribute as collection... i want
to declare get property G to access C

when i wrote

A.G[key]

also i could get A.C[key]
 
What type of object does the Command.Parameters[Parameter] call return -- a
SqlParameter, right? So, the indexer would look like:

public SqlParameter this[string Parameter]
{
get
{
return Command.Parameters[Parameter];
}
set
{
Command.Parameters[Parameter] = value;
}
}

Ken
 
Sadun Sevingen said:
but this give collection property to object... i want to access into an
collection in the object...

lets say... i have object A and it has C attribute as collection... i want
to declare get property G to access C

when i wrote

A.G[key]

also i could get A.C[key]

In your A class you need a property to get to your collection first.

public SqlParameterCollection Parameters
{
get
{
return this.pararmeters
}
set
{
this.parameters = value;
}
}

Then the collection class has the indexer

class Parameters
{
// indexer
public SqlParameter Parameter this[string Parameter]
{
get
{
return Command.Parameters[Parameter];
}
set
{
Command.Parameters[Parameter] = value;
}
}
}

SP
 
Back
Top