Can someone help me?

  • Thread starter Thread starter Eric Borden
  • Start date Start date
E

Eric Borden

I have created the following classes (psuedo code example):

BaseClass
protected method BaseClass.Foo(object Test) {
Test = new object();
}

MyClass : BaseClass
private object myProperty;
MyClass() {
Foo(myProperty)
}

AnotherClass
private MyClass myClass;
AnotherClass() {
myclass = new MyClass();
{

The issue I'm having is if you try to access myclass.myProperty
while in the constructor of AnotherClass,
myclass.myProperty is null.

However, if you remove BaseClass and define Foo in MyClass,
myclass.myProperty is not null while scope is in the constructor of
AnotherClass.

Can someone help me understand this,

Eric
 
From what it looks like to me, your problem is that you are expecting to
update a parameter that is passed by value.
BaseClass
protected method BaseClass.Foo(object Test) {
Test = new object();
}

should be declared
protected method BaseClass.Foo(ref object Test)

See
http://msdn.microsoft.com/library/en-us/csref/html/vclrfPassingMethodParameters.asp

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
 

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

Back
Top