C#中方法的详细介绍

本篇文章介绍了,C#中方法的详细说明。需要的朋友参考下

1.让方法返回多个参数

1.1在方法体外定义变量保存结果

复制代码 代码如下:

using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;

 namespace Method
 {
     class Program
     {
         public static int quotient;
         public static int remainder;
         public static void Divide(int x, int y)
         {
             quotient = x / y;
             remainder = x % y;
         }
         static void Main(string[] args)
         {
             Program.Divide(6,9);
             Console.WriteLine(Program.quotient);
             Console.WriteLine(Program.remainder);
             Console.ReadKey();

         }
     }
 }

1.2使用输出型和输入型参数
复制代码 代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Method
{
    class Program
    {
        public static void Divide(int x, int y, out int quotient, out int remainder)
        {
            quotient = x / y;
            remainder = x % y;
        }
        static void Main(string[] args)
        {
            int quotient, remainder;
            Divide(6,9,out quotient,out remainder);
            Console.WriteLine("{0} {1}",quotient,remainder);
            Console.ReadKey();
        }
    }
}

以上就是C#中方法的详细介绍的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 其他教程