delegate string strDelegate(string str);


  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4.   
  5. namespace DelegateApp  
  6. {  
  7.     delegate string strDelegate(string str);   
  8.   
  9.     class Program  
  10.     {  
  11.         //delegate string strDelegate(string str);  
  12.   
  13.         static string strReplace(string s)  
  14.         {  
  15.             return s.Replace(' ''_');  
  16.         }  
  17.   
  18.         static string strRemove(string s)  
  19.         {  
  20.             /* 
  21.             string temp = ""; 
  22.  
  23.             for (int i = 0; i < s.Length; i++) 
  24.             { 
  25.                 if (s[i] != ' ') 
  26.                 { 
  27.                     temp += s[i]; 
  28.                 } 
  29.             } 
  30.  
  31.             return temp; 
  32.              */  
  33.             StringBuilder sb = new StringBuilder(s.Length);  
  34.             for (int i = 0; i < s.Length; i++)  
  35.             {  
  36.                 if (s[i] != ' ')  
  37.                 {  
  38.                     sb.Append(s[i]);  
  39.                 }  
  40.             }  
  41.   
  42.             return sb.ToString();  
  43.         }  
  44.   
  45.         static string strReverse(string str)  
  46.         {  
  47.             if (string.IsNullOrEmpty(str))  
  48.             {  
  49.                 throw new ArgumentException("参数不合法");  
  50.             }  
  51.   
  52.             StringBuilder sb = new StringBuilder(str.Length);  
  53.             for (int index = str.Length - 1; index >= 0; index--)  
  54.             {  
  55.                 sb.Append(str[index]);  
  56.             }  
  57.             return sb.ToString();  
  58.         }      
  59.   
  60.         static void Main(string[] args)  
  61.         {  
  62.             strDelegate strD;  
  63.             string str;  
  64.   
  65.             strD = new strDelegate(strRemove);  
  66.             str = strD("asfa asdf asdf asdf asdf");  
  67.             Console.WriteLine(str);  
  68.   
  69.             strD = new strDelegate(strReplace);  
  70.             str = strD("asdf asdf");  
  71.             Console.Out.WriteLine(str);  
  72.   
  73.             strD = new strDelegate(strReverse);  
  74.             str = strD("asdf");  
  75.             Console.Out.WriteLine(str);  
  76.         }   
  77.     }  
  78. }  
  79. /* 
  80.  asfaasdfasdfasdfasdf 
  81. asdf_asdf 
  82. fdsa 
  83. 请按任意键继续. . . 
  84.  */  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值