Properties with different get and set types

P

PLS

VB.NET allows defining a property that has different get and set types
by doing this
Public Property fFlag(ByVal flag as flagEnumeration) As Boolean
Get
Return ...
End Get
Set(ByBal Value as Boolean)
...
End Set
End Property

What is the C# equivalent of this?

Thanks,
++PLS
 
D

Diainwater

I don't know exactly how to use VB.

Generally, we can use like this.

protected int ID
{
get
{
return _customerID;
}

public set
{
_customerID = value;
}
}
 
P

Peter Duniho

PLS said:
VB.NET allows defining a property that has different get and set types
by doing this
Public Property fFlag(ByVal flag as flagEnumeration) As Boolean
Get
Return ...
End Get
Set(ByBal Value as Boolean)
...
End Set
End Property

What is the C# equivalent of this?

I'm not really clear on what behavior you're looking for here. The code
you posted has a Boolean property, that returns a Boolean and has a
setter than takes a Boolean as a parameter.

So, I don't see how the property defined in the code you posted "has
different get and set types".

Now, that said, a C# property cannot have a parameter list as the
property you've posted does. You can have an indexer, which is like a
property that takes one or more parameters, and which looks a lot like
an array syntax-wise.

Maybe that's the kind of behavior you're trying to achieve?

http://msdn2.microsoft.com/en-us/library/6x16t2tx.aspx

Note that there can be only one indexer for a class. You can't define
an arbitrarily-named property that takes parameters.

Pete
 
C

Cor Ligthert[MVP]

PLS,

Do you know the sence of this, I don't see the reason at all.

VB.Net would in my opinion be better of by just following the type of the
member.
I have never used this.

I am glad this in my opinion not fine behaviour of VB (although it has
something more then C#) is not in C#.

However as Peter, I am currious why you want this.

(It is not optional in VB.Net and although properties are automaticly build
in VB.Net you see it forever in your code).

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top