odd reference problem

  • Thread starter Thread starter SteveK
  • Start date Start date
S

SteveK

I will just use code, I think that will be easiest way to explain this.


public struct Something
{
public string Name;
}






private void Form1_Load(object sender, System.EventArgs e)
{

Something Userinfo = new Something();

//
// Show login dialog
//
CLoginDlg loginDlg = new CLoginDlg(ref Userinfo);
if(loginDlg.ShowDialog() == DialogResult.Cancel)
{
CAppDebug.PrintDebugWarning();
Application.Exit();
}
}





private Something m_info;

public CLoginDlg(ref Something info)
{
// Required for Windows Form Designer support
InitializeComponent();

// TODO: Add any constructor code after InitializeComponent call
m_info = info;
}







then in the CLoginDlg class I assign values to m_info, then when control
returns back to Form1_Load() the values of Userinfo are all null.
I thought that in the CLoginDlg when I was assigning values to m_info I was
assigning values to a REFERENCE of Userinfo.
Confused?... I hope this makes sense to someone ;)

Thanks for any explanation!
Steve
 
changed struct to class and it works.
Everytime I try to use a struct in C# I get annoyed ;)


please disregard, unless you have a great way to explain to a newb' why
anyone would want to use a struct in C#
 
Back
Top