C # this keyword

First, on behalf of the current instance of the object

. 1       #region represents the current instance of the object
 2          public  String the Name = " global variable " ;
 . 3          public  void GetResult ()
 . 4          {
 . 5              the this .Name = " local variable " ;
 . 6              Console.WriteLine ( the this .Name);
 . 7          }
 . 8          #endregion

Second, this series configuration with the function

. 1      #region   with this series constructor
 2          public ThisKey ()
 . 3          {
 . 4              Console.WriteLine ( " no argument constructor " );
 . 5          }
 . 6  
. 7          public ThisKey ( String name): this ()
 . 8          {
 . 9              Console.WriteLine (name );
 10              Console.WriteLine ( " there argument constructor " );
 . 11          }
 12 is  
13 is          public ThisKey ( String text, int number) : this(text)
14         {
15 
16         }
17     #endregion

Third, extension methods

 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);

 

Guess you like

Origin www.cnblogs.com/GreatPerson/p/11099214.html