首页 > 其他 > 详细

C#中out的一种用法

时间:2014-07-07 14:53:25      阅读:304      评论:0      收藏:0      [点我收藏+]

1.当希望方法返回多个值时,声明out 方法很有用。

这样使方法可以有选择地返回值。

 

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

namespace 求数组最大最小值
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] numbers = { 45, 25, 14, 54, 85, 45, 4, 15, 47 };
            int myMax, myMin;
            myMax = FindMaxMin(numbers, out myMin);
            Console.WriteLine("max={0}  min={1}", myMax, myMin);
            Console.ReadKey();


        }

        static int FindMaxMin(int[] numbers, out int min)
        {
            int max;
            max = min = numbers[0];
            for (int i = 1; i < numbers.Length; i++)
            {
                if (numbers[i] > max)
                {
                    max = numbers[i];
                }
                if (numbers[i] < min)
                {
                    min = numbers[i];
                }

            }

            return max;
        }


    }
}

 

C#中out的一种用法,布布扣,bubuko.com

C#中out的一种用法

原文:http://www.cnblogs.com/SamllBaby/p/3815209.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!