zoukankan      html  css  js  c++  java
  • C#新特性

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace LocalApp.ConsoleApp
    {
        
    class Program
        
    {
            
    delegate void LambdaHandler();

            
    static void Main(string[] args)
            
    {
                
    //Func 封装一个具有 1 - 4 个参数并返回 TResult 参数指定的类型值的方法。

                Func
    <intstring> func = delegate(int i) return Convert.ToString(i * i); };
                Console.WriteLine(func(
    3));

                
    /******************************************/

                
    // lambda 表达式,i 参数
                Func<intstring> func2 = i => Convert.ToString(i * i);
                Console.WriteLine(func2(
    4));

                
    /******************************************/

                Func
    <stringstring> func3 = a => a.ToUpper();

                
    string[] array = "hebei","hubei","beijing","12" };

                IEnumerable
    <string> _array = array.Where<string>(b => b.EndsWith("i")); // array.Select(func3);

                
    foreach (string i in _array)
                    Console.WriteLine(i);

                
    /******************************************/

                Func
    <stringstringstringstringstring> __func = (a, b, c, d) => return a + "_" + b + "_" + c + "_" + d; };

                Console.WriteLine(__func(
    "h","e","l","lo"));

                
    /******************************************/


                Func
    <string> __func2 = () => "123456";

                Console.WriteLine(__func2());

                
    /******************************************/

                LambdaHandler lam 
    = () => Console.WriteLine( "1111111111");

                lam 
    += () => Console.WriteLine("22222222222");

                lam();

                
    /******************************************/
                
                
    //扩展方法
                string extTest = "hello world";

                Console.WriteLine(extTest.WordCount());

                
    foreach(string i in extTest.WordSplit())
                
    {
                    Console.WriteLine(i);
                }


                
    /******************************************/
                Console.ReadKey(
    true);
            }

        }


        
    /// <summary>
        
    /// 扩展方法
        
    /// </summary>

        public static class Extensions
        
    {
            
    public static int WordCount(this String str)
            
    {
                
    return str.Split(new char[] ' ''.''?' }, StringSplitOptions.RemoveEmptyEntries).Length;
            }


            
    public static string[] WordSplit(this String str)
            
    {
                
    return str.Split(new char[] {' ','.','?' }, StringSplitOptions.None);
            }

        }

    }

  • 相关阅读:
    Ubuntu下启用IPV6
    时间倒计时(天数+时+分+秒)
    移动端触摸移动相互调换位置
    js移动端点击隐藏和出现指定div(包含少许特效)
    将页面内容保存为图片显示,长按保存至本地(html2canvas)
    移动端触摸上拉隐藏指定模块内容,有过度效果(同时页面iscroll滚动)
    移动端图片缩放(包括滑动查看)
    移动端图片缩放(不包括滑动查看)
    IOS返回页面不刷新的问题
    datePicker(可以同时选择日期和时间)
  • 原文地址:https://www.cnblogs.com/yiki/p/1378446.html
Copyright © 2011-2022 走看看