J
Jarlaxle
I have 2 general c# questions I was hoping someone could answer...
1. Is it possible to return a struct by ref?...
class A
{
private mystruct _ms = new mystruct();
public mystruct ms
{
get { return _ms; }
}
}
since ms is a struct it returns a copy can therefore can't set values
on it. I think you should be able to doe something like...
get { return ref _ms; }
Any reason why this is not possible or any workarounds instead of making a
class or exposing the member directly?
2. is it possible to call a constructor with a base class?...
class A
{
A(B obj) {...}
A(C obj) {...}
}
object myo = MethodThatReturnsObjectOfBOrC();
A mya = new mya(myo);
Problem is I'd like to not know what could be returned from
MethodThatReturnsObjectOfBOrC so I'd like to avoid a switch statement. (could
add new types in future).
is it possible to cast at runtime and have the constructor address resolved
at runtime?...
Type t = myo.GetType();
A mya = new mya((t)myo);
Thanks.
1. Is it possible to return a struct by ref?...
class A
{
private mystruct _ms = new mystruct();
public mystruct ms
{
get { return _ms; }
}
}
since ms is a struct it returns a copy can therefore can't set values
on it. I think you should be able to doe something like...
get { return ref _ms; }
Any reason why this is not possible or any workarounds instead of making a
class or exposing the member directly?
2. is it possible to call a constructor with a base class?...
class A
{
A(B obj) {...}
A(C obj) {...}
}
object myo = MethodThatReturnsObjectOfBOrC();
A mya = new mya(myo);
Problem is I'd like to not know what could be returned from
MethodThatReturnsObjectOfBOrC so I'd like to avoid a switch statement. (could
add new types in future).
is it possible to cast at runtime and have the constructor address resolved
at runtime?...
Type t = myo.GetType();
A mya = new mya((t)myo);
Thanks.