zoukankan      html  css  js  c++  java
  • C# this 关键字

    一、代表当前实例对象

    1      #region 代表当前实例对象
    2         public string Name = "全局变量";
    3         public void GetResult()
    4         {
    5             this.Name = "局部变量";
    6             Console.WriteLine(this.Name);
    7         }
    8         #endregion

    二、用this串联构造函数

     1     #region  用this串联构造函数
     2         public ThisKey()
     3         {
     4             Console.WriteLine("无参数构造函数");
     5         }
     6 
     7         public ThisKey(string name) : this()
     8         {
     9             Console.WriteLine(name);
    10             Console.WriteLine("有参数构造函数");
    11         }
    12 
    13         public ThisKey(string text, int number) : this(text)
    14         {
    15 
    16         }
    17     #endregion

    三、扩展方法

     1       #region 扩展方法
     2         public int Count<T>(this IEnumerable<T> Source)
     3         {
     4             return Source.Count();
     5         }
     6 
     7         #endregion
     8 
     9             var sources = new List<People>
    10             {
    11                  new People()
    12                  {
    13                       ID=1,
    14                       Name="2"
    15                  },
    16                  new People()
    17                  {
    18                       ID=1,
    19                       Name="2"
    20                  }
    21             };
    22             var count = thisKey.Count<People>(sources);
    23             Console.WriteLine(count);
    将来的你,一定会感谢现在努力的自己!
  • 相关阅读:
    shell
    regionMatches方法
    ==
    使用INTO子句创建新表
    数据库除运算
    数据库笛卡尔积运算
    人生格言
    刚开通~
    Nginx:413 Request Entity Too Large
    ORACLE 查看并修改最大连接数
  • 原文地址:https://www.cnblogs.com/GreatPerson/p/11099214.html
Copyright © 2011-2022 走看看