I have a method passing a string to a class. For testing reasons I have used a button for now. I have searched in the forum for similar questions but they refer to php and other situation that I am unable to understand. The class strips out few characters from the string and assign the value to 3 different strings depending on the header. I need to return those 3 strings back to the caller and I have coded it as following.
Caller:
private void button4_Click(object sender, EventArgs e)
{
string a, b, c;
string invia = textBox8.Text.ToString();
Stripper strp = new Stripper();
strp.Distri(invia, out a, out b, out c);
textBox7.Text = a;
textBox7.Text = b;
textBox7.Text = c;}
Class:
class Stripper
{
public void Distri (string inArrivo, out string param1, out string param2, out string param3)
{
string corrente="";
string temperatura="";
string numGiri="";
string f = inArrivo;
f = f.Replace("<", "");
f = f.Replace(">", "");
if (f[0] == 'I')
{
string _corrente = f;
_corrente = _corrente.Replace("I", "");
corrente = _corrente;
}
else if (f[0] == 'T')
{
string _temperatura = f;
_temperatura = _temperatura.Replace("T", "");
temperatura = _temperatura;
}
else if (f[0] == 'N')
{
string _numGiri = f;
_numGiri = _numGiri.Replace("N", "");
numGiri = _numGiri;
}
param1 = corrente;
param2 = temperatura;
param3 = numGiri;
}
}
}
The code is working without problems but I am not sure if this is the correct way to achieve the returning of multiple values from a class. Is there a better way?