Property Assesor

  • Thread starter msnews.microsoft.com
  • Start date
M

msnews.microsoft.com

Is it possible to have a property return (get) one type but be assigned
(set) from another type?

Something like:

private int _InvoiceTypeID;

public InvoiceType InvoiceType
{
get
{
return this.GetInvoiceTypeFromDB(this._InvoiceTypeID);
}
set(int InvoiceTypeID)
{
this._InvoiceTypeID = (int)value;
}
}

Obviously this doesn't work. But it's what I want to accomplish. This may
also not be good practice as it is kind of confusing to have a property be
set/get with different types. If this is the case I will find another
way....
Josh
 
K

Kalpesh Shah

You can cheat the compiler by making it return object
While setting it, you know that it is an int, so using boxing-unboxing

While getting, you will return an object of InvoiceType. Only thing, is that
the client calling this method will have to cast it to (InvoiceType), since
this method will return object

HTH
Kalpesh
 

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