C#复习笔记(8)

参数数列

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

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);

     }


}

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值