将多个值从类返回到方法

Fel*_*ceM 2 c# variables return out

我有一个方法将字符串传递给类.出于测试原因,我现在使用了一个按钮.我在论坛中搜索了类似的问题,但他们提到了php和其他我无法理解的情况.该类从字符串中删除几个字符,并根据标题将值分配给3个不同的字符串.我需要将这3个字符串返回给调用者,并将其编码为以下内容.

呼叫者:

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;}
Run Code Online (Sandbox Code Playgroud)

类:

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;
        }
       }
      }
Run Code Online (Sandbox Code Playgroud)

代码工作没有问题,但我不确定这是否是从类中返回多个值的正确方法.有没有更好的办法?

Dam*_*ith 5

我认为在这种情况下创建类更好

   public class MyClass
    {
        public string Corrente { get; set; }
        public string Temperatura { get; set; }
        public string NumGiri { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

然后

public MyClass Distri(string inArrivo)
{
    // your code

    MyClass myclass = new MyClass() {
        Corrente = corrente, 
        NumGiri = numGiri, 
        Temperatura = temperatura 
    };
    return myclass;

}
Run Code Online (Sandbox Code Playgroud)

这就是你可以打电话的方式

Stripper strp = new Stripper();
MyClass myclass = strp.Distri(invia);
Run Code Online (Sandbox Code Playgroud)

//访问如下的值

textBox7.Text = myclass.NumGiri;
Run Code Online (Sandbox Code Playgroud)