C#完成向函數傳遞不定參數的辦法。本站提示廣大學習愛好者:(C#完成向函數傳遞不定參數的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#完成向函數傳遞不定參數的辦法正文
本文實例講述了C#完成向函數傳遞不定參數的辦法。分享給年夜家供年夜家參考。詳細完成辦法以下:
using System; class Min{ public int MinVla(params int [] nums){ int m; if (nums.Length == 0){ Console.WriteLine("Error: no arguments."); return 0; } m = nums[0]; foreach ( int val in nums){ if ( val < m){ m = val; } } return m; } } class ParamsDemo{ static void Main(){ Min ob = new Min(); int min; int a=10,b=20; min = ob.MinVla(a,b); Console.WriteLine("Minimum is " + min); min = ob.MinVla(a,b,-1); Console.WriteLine("Minimum is " + min); min = ob.MinVla(18,23,3,14,25); Console.WriteLine("Minimum is " + min); int [] args = {45,67,34,9,112,8}; min = ob.MinVla(args); Console.WriteLine("Minimum is " + min); } }
願望本文所述對年夜家的C#法式設計有所贊助。