• 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] + """;
                }
            }
    
    
        }
    }
  • 相关阅读:
    Leetcode 乘积最大子数组 (两种思路)
    C++string函数库-->to_string
    Zigzags CodeForces
    石子游戏(Leetcode每日一题)
    树形dp入门题(Leetcode 337. 打家劫舍 III)
    E
    背包九讲
    通过树状dp来求树的直径
    329. 矩阵中的最长递增路径(Leetcode每日一题)
    关于图的匹配,边覆盖,独立集,顶点覆盖
  • 原文地址:https://www.cnblogs.com/suanshun/p/7001659.html
Copyright © 2020-2023  润新知