C#如何实现传递bool类型的指针参数?

有没有办法这一句MessageBox.Show(Http.numble);放到主函数中去,并且不去改变方法Get_Check()的类型 

部分代码如下:

 这是封装好的一个类里面的方法  (这里面的 Http.Get是从网页上获取数据的一个方法)

unsafe public static bool Get_Check(string url, Dictionary<string, string> UseFor)

{
           
            Http.rel = Http.Get(url, UseFor);
            Http.numble = Http.rel.Substring(73, Http.rel.Length - 82);//从获取的文本数据中摘出自己想要的,通过了就会有PASS,没有通过就会有NG;
            if (Http.numble.Contains("NG") == true)
            {
                n = false;
                MessageBox.Show(Http.numble);
            } 
            else
                n = true;
            return n ;           
 }

这是主程序的调用这个方法

        private unsafe void Button2_Click(object sender, EventArgs e)
        {
            string url1 = "http://10.11.2.8:86/NPI.asmx/Sync_CheckStation";
            Dictionary<string, string> UseFor = new Dictionary<string, string> {
                {"sn",textBox1.Text},{"station",textBox2.Text},{"type","BZ"}
            };
            if(Http.Get_Check(url1, UseFor)==true)
            {
                MessageBox.Show("PASS");
            }
        }

猜你想要的是多个返回值,不改变现有返回值类型的话,只能动函数参数,至少有两种办法,一种是使用 out 参数。

使用 C# 的 out 关键字,加一个参数 `out string numble `,函数内部赋值它,外部就可以用。

另一种方式是你可以传入一个回调函数来处理额外的数据。

参考:https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/out-parameter-modifier