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

Property Assesor

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
"msnews.microsoft.com" <aa***@yahoo.com> wrote in message
news:eW**************@TK2MSFTNGP11.phx.gbl...
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

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.