C # interface

Source: Internet
Author: User

Interfaces can be defined within: indexers, properties, functions, events. cannot be accessed with access modifiers

1  Public  InterfaceIeventinterface2     {3         string  This[intIndex] {Get;Set; }//Indexer4list<string> MyList {Get;Set; }//Properties5         stringName {Get;Set; }//Properties6         EventEventHandler MyEventHandler;//Events7         voidMeth ();//Method8     }9 Ten      Public classInterfacetestclass:ieventinterface One     { A          Public string  This[intIndex//Indexer Implementation -         { -              the              Get -              { -                 if(index>0&&index<=mylist.count-1) -                   returnMylist.toarray () [index]; +                 return "out of Bounds"; -              } +              Set A              { atMylist[index] =value; -              } -         } -          Publiclist<string> MyList {Get;Set; }//Property Implementation -          Public  stringName {Get;Set; }//Property Implementation -          Public voidMeth ()//Method Implementation in         { -Console.WriteLine ("Meth"); to         } +          Public EventEventHandler MyEventHandler;//Event Implementation -  the          Public voidInvokemyeventhandler ()//methods for invoking events *         { $MyEventHandler (NULL,NULL);Panax Notoginseng         } -     } the class Program +     { A          Public Static voidMymethed (ObjectSender,eventargs e) the         { +Console.WriteLine ("mymethed"); -         } $  $         Static voidMain (string[] args) -         { -  the             varmyclass=NewInterfacetestclass (); -myclass.mylist=Newlist<string> () {"a","b","C"};Wuyi             varStr= myclass[1];//Indexer Usage the Console.WriteLine (str); -              Wumyclass[1] ="BB"; - Myclass.meth (); Aboutmyclass.myeventhandler+=NewEventHandler (mymethed);//Event Add function $  - Myclass.invokemyeventhandler (); -              -             A         } +}

C # interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.