本文介绍了在方法中使用OUT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  static void Main(string[] args)
        {
            Console.WriteLine("Choose 1 to continue or 0 to exit");
            int choice = int.Parse(Console.ReadLine());
            if (choice==0)
            {
                Console.WriteLine("Bye");
                System.Environment.Exit(0);
            }
            do
            {

                Check(out float i,"MEssage");
                Check(out float j,"MEssage");
                Check(out float k,"MEssage");

            } while (choice==1);
        }

        public static void Check(out float param, string message)
        {
            bool isNumber;
            string input;
            do
            {
                input = Console.ReadLine();
                isNumber = float.TryParse(input, out param);
            } while (!isNumber);
        }
}





我的尝试:



我试图只检查一次用户输入,然后将其作为方法调用,如果错误则不让用户继续,但是在调用方法时出现错误。我无法完全理解方法中OUT的用法。



What I have tried:

I am trying to check users input only once and then call it as a method and not letting the user to continue if it is wrong but when calling the method there is an error. I can not fully understand the usage of OUT in methods.

推荐答案

float i, j, k;
Check(out i,"MEssage");
Check(out j,"MEssage");
Check(out k,"MEssage");

// Now you can use i, j and k...



[]

[]


这篇关于在方法中使用OUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:37