The useful part of delegates is so a method can be passed from one object to another . As we know a method represents some type of action that an object can do . That action is implemented in the method definition itself within the class the method is declared . With a delegate the implementation of the method or part of the method contained in the class, can be delegated to another class . Here, we have a simple example to understand delegates . We have a Playlist class that allows to add songs to a playlist . The Playlist class provides a method called ShowPlaylist that prints out all the songs in the playlist . class Playlist {// code eliminated for brevity public void ShowPlaylist () {foreach (Song song in this.list) {Console.WriteLine (" Song Title: {0}". song.Title);}}}
Syntax arr.reduce (callbackFunction, [initialValue]) តើការកាត់បន្ថយធ្វើ? កាត់បន្ថយគឺជាអនុគមន៍ដែលរង្វិលជុំតាមរយៈការអារេមួយ. ប្រតិបត្ដិការត្រូវបានដំណើរការលើអារេតាមរយៈមុខងារ callback មួយ. នៅចុងបញ្ចប់នៃប្រតិបត្តិការនៅលើអារេ, reduce returns a single value Reduce can be used, ឧទាហរណ៍, to total a shopping cart Example let arr...