By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,460 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,460 IT Pros & Developers. It's quick & easy.

Property

P: n/a
Hi.

I'd want to know if it is possible in C # to declare one property analogous
to following (written in VB):

Property PropertyName (ByVal Index As Integer) As Object
Get
Return List.Item(Index)
End Get
Set (ByVal Value As Object)
List.Item(Index) = Value
End Set
End Property

(where List is an object of class CollectionBase).

The problem resides in the fact that in C # I don't succeed to declare a
property that receives a parameter (in this case an integer, but in a
generalized manner whichever type of object).

I've seen that an analogous thing can be made through indexer, but in the
case I want to pass more than one parameter or a parameter that isn't an
Integer?

More faster, someone can tell me why this translantion in C# of that VB code
fragment doesn't work?

public Object PropertyName (int Index) {
get {
return List.Item(Index);
}
set {
List.Item(Index)=value;
}
}

Thanks everyone.
Hi.
Roberto Sartori.

Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
http://www.harding.edu/USER/fmccown/...omparison.html

Roberto Sartori wrote:
Hi.

I'd want to know if it is possible in C # to declare one property analogous
to following (written in VB):

Property PropertyName (ByVal Index As Integer) As Object
Get
Return List.Item(Index)
End Get
Set (ByVal Value As Object)
List.Item(Index) = Value
End Set
End Property

(where List is an object of class CollectionBase).

The problem resides in the fact that in C # I don't succeed to declare a
property that receives a parameter (in this case an integer, but in a
generalized manner whichever type of object).

I've seen that an analogous thing can be made through indexer, but in the
case I want to pass more than one parameter or a parameter that isn't an
Integer?

More faster, someone can tell me why this translantion in C# of that VB code
fragment doesn't work?

public Object PropertyName (int Index) {
get {
return List.Item(Index);
}
set {
List.Item(Index)=value;
}
}

Thanks everyone.
Hi.
Roberto Sartori.



Nov 16 '05 #2

P: n/a
Thanks.
"Supra" <su*****@rogers.com> ha scritto nel messaggio
news:HW********************@twister01.bloor.is.net .cable.rogers.com...
http://www.harding.edu/USER/fmccown/...omparison.html

Roberto Sartori wrote:
Hi.

I'd want to know if it is possible in C # to declare one property analogousto following (written in VB):

Property PropertyName (ByVal Index As Integer) As Object
Get
Return List.Item(Index)
End Get
Set (ByVal Value As Object)
List.Item(Index) = Value
End Set
End Property

(where List is an object of class CollectionBase).

The problem resides in the fact that in C # I don't succeed to declare a
property that receives a parameter (in this case an integer, but in a
generalized manner whichever type of object).

I've seen that an analogous thing can be made through indexer, but in the
case I want to pass more than one parameter or a parameter that isn't an
Integer?

More faster, someone can tell me why this translantion in C# of that VB codefragment doesn't work?

public Object PropertyName (int Index) {
get {
return List.Item(Index);
}
set {
List.Item(Index)=value;
}
}

Thanks everyone.
Hi.
Roberto Sartori.


Nov 16 '05 #3

P: n/a
SP
Look at indexers in the C# help.

public class MyCollection : CollectionBase
{
public MyItem this[int index, other parameters....]
{
get
{
return (MyItem)List[index];
}
set
{
List[index] = value;
}
}
}

or in your case MyItem would be Object although CollectionBase is generally
used for strongly typed collections so you cast the Object to the
collection's Item type rather then returning type Object.

SP
"Roberto Sartori" <ro***************@email.it> wrote in message
news:cb**********@lacerta.tiscalinet.it...
Hi.

I'd want to know if it is possible in C # to declare one property analogous to following (written in VB):

Property PropertyName (ByVal Index As Integer) As Object
Get
Return List.Item(Index)
End Get
Set (ByVal Value As Object)
List.Item(Index) = Value
End Set
End Property

(where List is an object of class CollectionBase).

The problem resides in the fact that in C # I don't succeed to declare a
property that receives a parameter (in this case an integer, but in a
generalized manner whichever type of object).

I've seen that an analogous thing can be made through indexer, but in the
case I want to pass more than one parameter or a parameter that isn't an
Integer?

More faster, someone can tell me why this translantion in C# of that VB code fragment doesn't work?

public Object PropertyName (int Index) {
get {
return List.Item(Index);
}
set {
List.Item(Index)=value;
}
}

Thanks everyone.
Hi.
Roberto Sartori.

Nov 16 '05 #4

P: n/a
Your VB property example won't compile either. Just use separate get/set
functions or an indexer (C#).

kevin

"Roberto Sartori" <ro***************@email.it> wrote in message
news:cb**********@lacerta.tiscalinet.it...
Hi.

I'd want to know if it is possible in C # to declare one property analogous to following (written in VB):

Property PropertyName (ByVal Index As Integer) As Object
Get
Return List.Item(Index)
End Get
Set (ByVal Value As Object)
List.Item(Index) = Value
End Set
End Property

(where List is an object of class CollectionBase).

The problem resides in the fact that in C # I don't succeed to declare a
property that receives a parameter (in this case an integer, but in a
generalized manner whichever type of object).

I've seen that an analogous thing can be made through indexer, but in the
case I want to pass more than one parameter or a parameter that isn't an
Integer?

More faster, someone can tell me why this translantion in C# of that VB code fragment doesn't work?

public Object PropertyName (int Index) {
get {
return List.Item(Index);
}
set {
List.Item(Index)=value;
}
}

Thanks everyone.
Hi.
Roberto Sartori.

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.