In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The following is illustrated by a code example
Define a Npc class, OA credit tray platform customization (enterprise E: 217 1793)
/ / define the Npc class
Public class Npc
{
/ / define field variables
Private int npcId
Private string name
Public Npc () {}
/ / define the properties corresponding to field variables
Public int NpcID
{
Get {return npcId;}
Set {npcId = value;}
}
Public string Name
{
Get {return name;}
Set {name = value;}
}
}
When you use the Npc class, you want to call a method that sets both NpcId and Name, but you don't write such a method when defining the Npc class. What to do, you can add such a method directly to the Npc class, or you can derive a subclass from the Npc class, and then add a method that meets the requirements in the subclass. Another way is to extend a method directly into the Npc class as we're going to talk about today.
The following code extends a new method directly to the Npc class
/ / extend the Npc class
Public static class ExtendNpc
{
/ / extend a method to the Npc class
/ / SetIDName (this Npc npc, int id, string name)
Public static void SetIDName (this Npc npc, int id, string name)
{
Npc.NpcID = id
Npc.Name = name
}
}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.