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