Oleg.Budeanu
Oleg.Budeanu

Reputation: 35

Store and access multiple values in c#

I am searching an easy and elegant way to keep several string and access it the same easy way in winforms application.

I have 10 string variables which I am using in one form, every time I make some change, pressing a button or any other action I need to renew those values.

Here it is the code how I am filling those variables with data:

string cDir = clientsbox2.SelectedItem.ToString();
string ClientPath = PMFunc.XMLDir(settings) + cDir;
string ProjectPath = PMFunc.XMLDir(settings) + cDir + @"\"
                     + outlookGrid1.CurrentRow.Cells[0].Value.ToString();
string pathString = Path.Combine(ProjectPath);
string path3DString = Path.Combine(ProjectPath + @"\02-3D");
string pathDatosString = Path.Combine(ProjectPath + @"\01-Datos");
string pathImagenesString = Path.Combine(ProjectPath + @"\03-Imagenes");
string pathProcesso3D = Path.Combine(ProjectPath + @"\02-3D\Processo");
string pathTrafico3D = Path.Combine(ProjectPath + @"\02-3D\Trafico");
string maxfilename = path3DString + @"\" + clientsbox2.SelectedItem.ToString() 
                    + @"-" + PMFunc.ReturnWipNumber(cDir,
                    outlookGrid1.CurrentRow.Cells[0].Value.ToString().ToString(),
                    outlookGrid1.CurrentRow.Cells[2].ToString()) + @"-"
                    + outlookGrid1.CurrentRow.Cells[0].Value.ToString() + @"-"
                    + PMFunc.ReturnCopyNumber(cDir,
                    outlookGrid1.CurrentRow.Cells[0].Value.ToString().ToString(),
                    outlookGrid1.CurrentRow.Cells[2].ToString()) + @".max";

As you can see some of it is being generated by some objects from the Form, and some are being filled by methods from PMFunc class which I have in separate file.

So every time I need to fill these variables I am using this block of code, but I am sure there is a way to do that easier.

Can you advice me please?

Upvotes: 0

Views: 316

Answers (1)

Tim Jarvis
Tim Jarvis

Reputation: 18815

Another option would be to make these variables into form properties with getters that read the component values.

public string cdir
{
    get
    {
       return clientsbox2.SelectedItem.ToString();
    }
}

... etc

Upvotes: 2

Related Questions