zoukankan      html  css  js  c++  java
  • (20140714作业)超必杀都是从小招数中提炼出来的!C#基础技能汇总

    作业要求是汇总之前学过的基础知识,可以说 学的乱七八糟,一塌糊涂! 这里写了石头提及的几个重点,比如泛型,委托。

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Reflection;
     5 using System.Text;
     6 using System.Threading.Tasks;
     7 
     8 namespace ConsoleApplication1
     9 {
    10     class Program
    11     {
    12         static void Main(string[] args)
    13         {
    14             Console.ForegroundColor = ConsoleColor.Yellow;
    15             ListTest();
    16             StringTest();
    17             Console.WriteLine("使用委托----------");
    18             testHandler th = new testHandler(ListTest);
    19             th += StringTest;
    20             th -= StringTest;                  //21             //   th -= ListTest;                  //
    22 
    23             th.Invoke();                        //
    24             Console.Read();
    25         }
    26 
    27         /// <summary>事务使用</summary>
    28         delegate void testHandler();
    29 
    30         //存数据
    31         static List<string> list = new List<string>();
    32         /// <summary>枚举、泛型、 运行后list才有值</summary>
    33         public static void ListTest()
    34         {
    35             Console.WriteLine("----------------枚举-----------------");
    36             Console.WriteLine("输出TypeCode:");
    37             foreach (string name in Enum.GetNames(typeof(TypeCode)))
    38             {
    39                 Console.WriteLine(name + "	");
    40                 list.Add(name);
    41             }
    42         }
    43         /// <summary>字符串</summary>
    44         public static void StringTest()
    45         {
    46             Console.WriteLine("----------------字符串-----------------");
    47             list = list.Where(i => i.Contains("Int")).ToList<string>();
    48             Console.WriteLine("字符串的处理:
     每种Int类型 保留最后2个字符");
    49             //foreach (var item in list)
    50             //{
    51             //    Console.WriteLine(item.Substring(item.Length - 2)); ;
    52             //}
    53             list.ForEach(x =>
    54             {
    55                 Console.WriteLine(x.Substring(x.Length - 2));
    56 
    57             });
    58 
    59         }
    60     }
    61 }

    这次作业,我做的是获取TypeCode类里面枚举值,用来做后面的测试数据,当然全都是字符串。
    处理字符串,找到包含“INT”的项,截取他们最后2位字符(数字部分)输出。
    以下是运行结果:

    对委托的理解 还停留在他是一个“方法容器”的概念,具体用法还在学习中。

    th -= StringTest; // ① 
    // th -= ListTest; // ②
    

      

    如上代码:注释掉① 取消注释② 则运行结果为空 
    两个全部取消注释 ,在③处报空异常

    在这次的作业中提及到的一些知识点有:
    循环、泛型、枚举、委托、字符串截取和拉姆达表达式。

    欢迎批评指正。

    超必杀都是从小招数中提炼出来的!

  • 相关阅读:
    JS 子窗口向父窗口传值
    CSS垂直居中盘点
    Javascript关于BOM与DOM详解
    css inline元素与inline-block,block元素
    CSS定位
    mysql 8+ 忘记root密码 解决方案
    php 引入其他文件中的变量
    h5 input无法输入问题 屏蔽长按事件
    关于ajax请求status 200 却进入error 回调函数或显示跨域问题的解决方案及原因
    vue 中使用 lazyload 插件 数据更图片不更新 的原因 及解决方案
  • 原文地址:https://www.cnblogs.com/Ex-Oj/p/3851418.html
Copyright © 2011-2022 走看看