Thanks a lot Pete,
And also for showing me how to actually return the values using
a class. Now I know how to do them both.
Thanks again
Steve
class PromptRecord
{
public readonly string uName;
public readonly string uAddress;
public readonly string uNotes;
public PromptRecord(string uName, string uAddress, string uNotes)
{
this.uName = uName;
this.uAddress = uAddress;
this.uNotes = uNotes;
}
}
Then in your dialog class, instead of the properties you showed, have
something like this:
public PromptRecord Data
{
get { return new PromptRecord(textBoxName.Text,
textBoxAddress.Text, textBoxNotes.Text); }
}
Finally, in the code that shows the dialog:
using (frmData GetData = new frmData())
{
if (GetData.ShowDialog() == DialogResult.OK)
{
PromptRecord data = GetData.Data;
UserName = data.uName;
UserAddress = data.uAddress);
UserNotes = data.uNotes);
}
}
(I made the fields "readonly" as an alternative to writing read-only
properties for the class...it seems to me that the data for sure should be
read-only, and putting properties in there seems like overkill for
something that's basically just a bucket to stick some data into for later
retrieval).
Note that if the client of the dialog class isn't careful to retrieve the
Data property just once, multiple instances of the PromptRecord class wind
up getting created. This is a theoretical performance issue, but in
reality it's negligible. That said: you could add some complexity to deal
with that possibility, but also it's a good example of how the "one
property per field" paradigm is simpler and less prone to accidental
misuse.
Pete