C#中当参数超过5个时,建议用结构来传递多个参数。
示例代码如下:
1 public struct MyStruct 2 { 3 public string str; 4 public int number; 5 } 6 7 class Program 8 { 9 static void Main(string[] args) 10 { 11 MyStruct myStruct = new MyStruct(); 12 myStruct.str = "Number :"; 13 myStruct.number = 100; 14 MyClass mc = new MyClass(); 15 mc.output(myStruct); 16 Console.ReadKey(); 17 } 18 } 19 20 class MyClass 21 { 22 public void output(MyStruct ms) 23 { 24 Console.WriteLine(ms.str + ms.number.ToString()); 25 } 26 }
时间: 2024-10-11 01:16:23