In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "what is the method of realizing anonymity in C#". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The C# anonymous method allows us to define blocks of code that are acceptable to the delegate object. This feature leaves out an extra step that we want to pass to a delegate's small block of code when we create the delegate. It also eliminates the confusion of small and medium-sized methods in class code. Let's see: for example, we have a collection of strings named MyCollection. This class has a method: get all the items in the collection that meet the user-provided filtering criteria, and the caller decides whether a particular item in the collection meets the criteria and is retrieved as part of the returned array from this method.
Public class MyCollection {public delegate bool SelectItem (string sItem); public string [] GetFilteredItemArray (SelectItem itemFilter) {List sList = new List (); foreach (string sItem in m_sList) {if (itemFilter (sItem) = = true) sList.Add (sItem);} return sList.ToArray ();} public List ItemList {get {return mechsList;}} private List m_sList = new List ();}
We can use the classes defined above to write the code as follows:
Public class Program {public static void Main (string [] args) {MyCollection objMyCol = new MyCollection (); objMyCol.ItemList.Add ("Aditya"); objMyCol.ItemList.Add ("Tanu"); objMyCol.ItemList.Add ("Manoj"); objMyCol.ItemList.Add ("Ahan"); objMyCol.ItemList.Add ("Hasi"); / / get an array of character items in the set that begin with the letter'A 'string [] AStrings = objMyCol.GetFilteredItemArray (FilterStringWithA) Console.WriteLine ("- Strings starting with letter''Console.WriteLine' -"); foreach (string s in AStrings) {Console.WriteLine (s);} / / get the array of character items in the collection that begin with the letter'T' string [] TStrings = objMyCol.GetFilteredItemArray (FilterStringWithT); Console.WriteLine ("- Strings starting with letter''Tunable' -"); foreach (string s in TStrings) {Console.WriteLine (s) }} public static bool FilterStringWithA (string sItem) {if (sItem [0] = =''Aging') return true; else return false;} public static bool FilterStringWithT (string sItem) {if (sItem [0] = =''tasked') return true; else return false;}} "what is the way for C# to achieve anonymity"? thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.