Beginner question on access modifiers

  • Thread starter Thread starter Frank
  • Start date Start date
F

Frank

I have a form implemented as shown below. If I define the tp_
data member as private it is always null in the Click event
handler. When I remove private and let it use the default
access ( which I think is private ) then it is ok ( non null ) in the
Click handler. I don't understand why?

public partial class Properties_Form_TiePoint : Form
{
// this declaration works ok
Tiepoint tp_ = new Tiepoint();

// this one doesn't
// private Tiepoint tp_ = new Tiepoint();

public Tiepoint ImageTiePoint
{
get { return tp_; }
set { tp_ = value; }
}

public Properties_Form_TiePoint()
{
InitializeComponent();
//tp_ is ok here
}


private void OKButton_Click(object sender, EventArgs e)
{
// tp_ is null if declared with private
tp_.Name = TiepointName_Text.Text;

DialogResult = DialogResult.OK;
}
}

Thanks for any answers
Frank
 
I have a form implemented as shown below. If I define the tp_
data member as private it is always null in the Click event
handler. When I remove private and let it use the default
access ( which I think is private ) then it is ok ( non null ) in the
Click handler. I don't understand why?

No, it doesn't make sense. As you said yourself, private is the
default so the result should be the same. I think there's something
else in your code that's causing it. Can you simplify your code to a
small complete program that reproduces the problem?


Mattias
 
Back
Top