N
Nak
Hi there,
I have only just started using C# after becoming more than competent
with VB.NET. I have come across something that has confused me slightly, it
regards properties.
In VB.NET it is possible to pass a value to a property (similar to an
Indexer) but without it actually being an indexer, for example
Public Property layers(ByVal iKey As Object) As Byte(,)
Get
'get an item out of a hastable object, using iKey as the key
End Get
Set(ByVal Value As Byte(,))
'set an item in a hashtable, using iKey as the key
End Set
End Property
I would have thought that you could write something very similar in C#,
by writing,
public Byte[,] layers(Object iKey)
{
get
{
'get an item out of a hastable object, using iKey as the key
}
set
{
'set an item in a hashtable, using iKey as the key
}
}
But it seems that I am very wrong, and indeed even the Hashtable class
is used slightly differently in C#, rather than using a property that would
be layed out very similar to the above you have to use an Indexer, this is
all very well but you can only have 1 indexer per class as you can't even
name the indexer.
Is the only way to get around this to have 2 methods to access the
object, 1 to set and 1 to get? Would that be why some classes have
setMyValue rather than MyValue? Thanks loads in advance
Nick.
--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."
Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
I have only just started using C# after becoming more than competent
with VB.NET. I have come across something that has confused me slightly, it
regards properties.
In VB.NET it is possible to pass a value to a property (similar to an
Indexer) but without it actually being an indexer, for example
Public Property layers(ByVal iKey As Object) As Byte(,)
Get
'get an item out of a hastable object, using iKey as the key
End Get
Set(ByVal Value As Byte(,))
'set an item in a hashtable, using iKey as the key
End Set
End Property
I would have thought that you could write something very similar in C#,
by writing,
public Byte[,] layers(Object iKey)
{
get
{
'get an item out of a hastable object, using iKey as the key
}
set
{
'set an item in a hashtable, using iKey as the key
}
}
But it seems that I am very wrong, and indeed even the Hashtable class
is used slightly differently in C#, rather than using a property that would
be layed out very similar to the above you have to use an Indexer, this is
all very well but you can only have 1 indexer per class as you can't even
name the indexer.
Is the only way to get around this to have 2 methods to access the
object, 1 to set and 1 to get? Would that be why some classes have
setMyValue rather than MyValue? Thanks loads in advance
Nick.
--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."
Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\