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; // ②
    

      

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

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

    欢迎批评指正。

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

  • 相关阅读:
    hdu 4970 树状数组 “改段求段”
    hdu 2242 无向图/求用桥一分为二后使俩个bcc点权值和之差最小并输出 /缩点+2次新图dfs
    hdu3715 2-sat+二分
    hdu 3639 有向图缩点+建反向图+搜索
    hdu 3072 有向图缩点成最小树形图计算最小权
    hdu 3061 hdu 3996 最大权闭合图 最后一斩
    hdu 3879 hdu 3917 构造最大权闭合图 俩经典题
    hdu 4738 无向图缩点断桥 // 细节坑题
    hdu3452 无向树去掉最小的边集使任何叶子与根不连通 / 最小割
    hdu 3657 最小割的活用 / 奇偶方格取数类经典题 /最小割
  • 原文地址:https://www.cnblogs.com/Ex-Oj/p/3851418.html
Copyright © 2011-2022 走看看