Using System; Using System. Collections. Generic; Using System. Linq; Using System. Text; Using System. Threading. Tasks; Namespace AppConsole { /// <Summary> /// Common user /// </Summary> Public class User { /// <Summary> /// Global variable /// </Summary> Dictionary <string, object> dictInfo = null; /// <Summary> /// Constructor /// </Summary> Public User () { DictInfo = new Dictionary <string, object> (); } /// <Summary> /// Overload the constructor /// </Summary> /// <Param name = "UserID"> </param> /// <Param name = "UserName"> </param> Public User (int UserID, string UserName) { This. UserName = UserName; This. ID = UserID; } /// <Summary> /// This, [1] usage, Indexer /// </Summary> /// <Param name = "name"> </param> /// <Returns> </returns> Public object this [string name] { Get {return dictInfo [name];} Set {dictInfo [name] = value ;} } /// <Summary> /// No. /// </Summary> Public int ID {get; set ;} /// <Summary> /// User Name /// </Summary> Public string UserName {get; set ;} /// <Summary> /// This parameter is used as a parameter. /// </Summary> Public void Said () { New VIP (). Say (this ); } } /// <Summary> /// Member /// </Summary> Public class VIP: User { /// <Summary> /// Points /// </Summary> Public int integral {get; set ;} /// <Summary> /// Constructor /// </Summary> Public VIP () { ID = 520; Integral = 1000; } /// <Summary> /// This is the [3] usage. this () is used to call a non-argument constructor. /// </Summary> /// <Param name = "UserName"> </param> Public VIP (string UserName) : This () { This. UserName = UserName; } /// <Summary> /// Overload the constructor /// </Summary> /// <Param name = "UserID"> </param> /// <Param name = "UserName"> </param> Public VIP (int UserID, string UserName) : Base (UserID, UserName) { } /// <Summary> /// Say Method /// </Summary> /// <Param name = "user"> </param> Public void Say ([LCQAttribute] User user) { Console. WriteLine (string. Format ("Hi, everyone! My ID is {0}. You can call me {1 }! ", User. ID, user. UserName )); } } /// <Summary> /// Static class to extend the User class /// </Summary> Public static class Helper { /// <Summary> /// Method [4]: this extends the User class /// </Summary> /// <Param name = "user"> </param> Public static void Sing (this User user) { Console. WriteLine (string. Format ("Hi, everyone! My ID is {0}. You can call me {1 }! ", User. ID, user. UserName )); } } /// <Summary> /// Feature class: specifies that a feature is only applicable to parameters of methods and methods. /// </Summary> [System. AttributeUsage (AttributeTargets. Method | AttributeTargets. Parameter)] Public class LCQAttribute: System. Attribute { } } |