zoukankan      html  css  js  c++  java
  • C#基础知识二之this关键字

    this关键字

    • 引用类的当前实例,包括继承而来的方法,通常可以省略。
            public class Person
            {
                public string Name { get; set; }
                public int Age { get; set; }
                public Person(string Name, int Age)
                {
                    this.Age = Age;
                    this.Name = Name;
                }
            }
    •  将对象作为参数传递到其他方法。
            public class Person
            {
                public string Name { get; set; }
                public int Age { get; set; }
                public Person(string Name, int Age)
                {
                    this.Age = Age;
                    this.Name = Name;
                }
                public void CallTest(Person person)
                {
                    Console.WriteLine(person.Name + person.Age);
                }
                public void Call()
                {
                    CallTest(this);
                }
            }
    • 声明索引器
            public class Person
            {
                string[] PersonList = new string[10];
                public string this[int param]
                {
                    get { return PersonList[param]; }
                    set { PersonList[param] = value; }
                }
            }
  • 相关阅读:
    洛谷 P1313 计算系数
    洛谷 P1088 火星人
    洛谷 P1049 装箱问题
    P5016 龙虎斗
    洛谷P1208
    求lca
    没有上司的舞会
    最短路spfa
    懒羊羊找朋友
    简单的图论问题之单源最短路dijkstra算法
  • 原文地址:https://www.cnblogs.com/liujie2272/p/5399603.html
Copyright © 2011-2022 走看看