zoukankan      html  css  js  c++  java
  • c# 简单委托例子

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    
    namespace _05委托
    {
        //声明一个委托
        public delegate string DelProStr(string str);//既可以有参数,也可以有返回值
        class Program
        {
            static void Main(string[] args)
            {
                //1、Test为什么可以作为参数传递
                //2、Test的参数为什么必须只能是object类型
                //Thread th = new Thread(Test);//委托
    
                string[] names = { "abCcDE", "FghIJkl", "mNOpqRST", "uvWXYz" };
    
                //创建了一个委托对象
    
                //在这new或者不new委托对象,编译的时候依然会new一个委托对象
                DelProStr del = SToUpper;//函数可以直接赋值给一个委托
    
    
    
                ProcessStr(names,del);
                //for (int i = 0; i < names.Length; i++)
                //{
                //    names[i] = del(names[i]);
                //}
    
                ////ProcessStr(names, SSYH);
    
                //foreach (string item in names)
                //{
                //    Console.WriteLine(item);
                //}
                Console.ReadKey();
                //1、统一 转成大写
                //2、统一的 转成小写
                //3、加双引号
            }
    
            static void ProcessStr(string[] names, DelProStr del)
            {
                for (int i = 0; i < names.Length; i++)
                {
                    names[i] = del(names[i]);
                    //names[i]=SToUpper(names[i]);
                }
            }
    
            static string SToUpper(string name)
            {
                return name.ToUpper();
            }
    
            static string SToLower(string name)
            {
                return name.ToLower();
            }
    
            static string SSYH(string name)
            {
                return """ + name + """;
            }
    
    
            static void StrToUpper(string[] names)
            {
                for (int i = 0; i < names.Length; i++)
                {
                    names[i] = names[i].ToUpper();
                }
            }
            static void StrToLower(string[] names)
            {
                for (int i = 0; i < names.Length; i++)
                {
                    names[i] = names[i].ToLower();
                }
            }
            static void StrSYH(string[] names)
            {
                for (int i = 0; i < names.Length; i++)
                {
                    names[i] = """ + names[i] + """;
                }
            }
    
    
        }
    }
  • 相关阅读:
    jQuery
    基于Js实现的UrlEncode和UrlDecode函数代码
    利用缓存、Timer间隔时间发送微信的实例,很有用的例子
    VisualStudio 自动排版等 快捷键
    正则表达式判断手机号码属于哪个运营商
    .Net常用方法汇总
    .NET中的三种Timer的区别和用法
    C# List和String互相转换
    Tempdb--TempDB Basic
    Tempdb--查看tempdb使用的脚本
  • 原文地址:https://www.cnblogs.com/suanshun/p/7001659.html
Copyright © 2011-2022 走看看