码迷,mamicode.com
首页 > 其他好文 > 详细

C#中out的一种用法

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

标签:style   blog   color   cti   for   io   

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的一种用法

标签:style   blog   color   cti   for   io   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!