Well, using an old trick I learned in C++, it can be done, sorta, but it's
still probably not a good idea:
public class A
{
private int _n;
public A(int n)
{
_n = n;
}
public AHelper TimesTwo
{
get
{
return new AHelper(this);
}
}
public int N
{
get { return _n; }
}
}
public class AHelper
{
private A _a;
public AHelper(A a)
{
_a = a;
}
public static implicit operator int(AHelper ah)
{
return ah._a.N *2;
}
public static implicit operator string (AHelper ah)
{
return String.Format("The value is {0}", ah._a.N *2);
}
}
public class MyClass
{
public static void Main()
{
A aa = new A(5);
int i = aa.TimesTwo;
string s = aa.TimesTwo;
Console.WriteLine("int ='{0}', string='{1}'", i, s);
}
}
--
Truth,
James Curran
[erstwhile VC++ MVP]
Home:
www.noveltheory.com Work:
www.njtheater.com
Blog:
www.honestillusion.com Day Job:
www.partsearch.com
"ORC" <or*@sol.dk> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Is it possible to overload properties - and if so - how?
Mayby there is another and better way to do what I'm trying to do so if
you have any suggestion I would be happy:
I have a number of properties to set and get values, but I want my
properties to be able to return a type that is corresponding to the target
variabel (and also be able to receive a type corresponding to the source)?
Thanks,
Ole