C#复习笔记(8) --参数数列

Posted on 2006-09-15 23:33  raekwon  阅读(141)  评论(0)    收藏  举报
 

参数数列

参数数列能够使多个相关的参数被单个数列代表,换就话说,参数数列就是变量的长度。

using System; 

class Test 



     
static void F(params int[] args) 

     


         Console.WriteLine(
"# 参数: {0}", args.Length); 

         
for (int i = 0; i < args.Length; i++

              Console.WriteLine(
"\targs[{0}] = {1}", i, args[i]); 

     }
 

 

     
static void Main() 

     


         F(); 

         F(
1); 

         F(
12); 

         F(
123); 

         F(
new int[] {1234}); 

     }
 

}
 

以下为输出结果: 
# 参数: 
0 
# 参数: 
1 
args[
0= 1 
# 参数: 
2 
args[
0= 1 
args[
1= 2 
# 参数: 
3 
args[
0= 1 
args[
1= 2 
args[
2= 3 
# 参数: 
4 
args[
0= 1 
args[
1= 2 
args[
2= 3 
args[
3]

using System;

 

public class TextBox

{

     TextBox()

     
{

         
this.GetMessage += new EventHandler(Print);

     }


     
public delegate void EventHandler(string message);

 

     
public event EventHandler GetMessage;

 

     
//OnGetMessage方法用于触发GetMessage

     
public void OnGetMessage(string message)

     
{

         
if (GetMessage != null)

         
{

              GetMessage(message);

         }


     }


     
public static void Main() 

     
{

         TextBox myTextBox 
= new TextBox();

         
//myTextBox.GetMessage += new EventHandler(Print);

         myTextBox.OnGetMessage(
"dfkd");

 

     }


     
public static void Print(string message)

     
{

         Console.WriteLine(message);

     }


}

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3