SoFunction
Updated on 2025-03-06

C# implements a method of passing uncertain parameters to a function

This article describes the method of C# implementing the method of passing uncertain parameters to a function. Share it for your reference. The specific implementation method is as follows:

using System;
class Min{
 public int MinVla(params int [] nums){
  int m;
  if ( == 0){
   ("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 = (a,b);
  ("Minimum is " + min);
  min = (a,b,-1);
  ("Minimum is " + min);
  min = (18,23,3,14,25);
  ("Minimum is " + min);
  int [] args = {45,67,34,9,112,8};
  min = (args);
  ("Minimum is " + min);
 }
}

I hope this article will be helpful to everyone's C# programming.