Interfaces in C #
Interface
[Public|protected|private] Interface InterfaceName
{
Mothed
Propery
Event
Delegate
}
When implementing an interface, the difference between the interface name and the interface
No difference between the eg:
public interface Imyshow
{
void Show ();
}
public class Myshow:imyshow
{
public void Show ()//must be written to the public if write void Show () error
{
System.Console.Write ("Without Interface Name");
}
}
public class Mymain
{
public static void Main ()
{
To define a reference with a class
Myshow obj=new myshow ();
Obj. Show ();
Using an interface reference method
Imyshow obj2=new myshow ();
Obj2. Show ();
}
}
With Interface name
public interface Imyshow
{
System.Console.Write ("with Interface name");
}
public class Myshow:imyshow
{
void Imyshow.show ()//cannot be preceded with any qualifier
{
System.Console.Write ("with Interface name");
}
}
public class Mymain
{
public static void Main ()
{
Myshow obj=new myshow ();
Obj. Show ()//illegal because the qualifier is added, this method belongs to one of the experts ' references and can only be referenced by an interface.
Imyshow obj2=new myshow ();
Obj2. Show ();
}
}
I want to leave a question for C # 's hobby after reading the above content. Would you please join us for a discussion
public interface Imyshow
{
void Show ();
}
public interface IMyShow2
{
void Show ();
}
public class Myclass:imyshow,imyshow2
{
Public Myclass ()
{
Class Class1
{
<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main (string[] args)
{
Imyshow obj2=new Myclass ();
Obj2. Show ();
Imyshow obj1=new Myclass ();
Obj1. Show ();
Myclass obj=new Myclass ();
Obj. Show ();
}
}
}
Namespace Wfgspace
Public Interface Imyshow
Sub Show ()
Function Add (ByVal A As Integer, ByVal b As Integer) As Integer
End Interface
Public Interface IMyShow2
Sub Show ()
Function Add (ByVal A As Integer, ByVal b As Integer) As Integer
End Interface
Public Class mycls:implements Imyshow, IMyShow2
Private Ivalue as Integer
Sub Show () Implements imyshow.show
System.Console.Write ("Wfng fu Guo")
End Sub
Sub Show2 () Implements imyshow2.show
System.Console.Write ("WFG")
End Sub
Function ADD2 (ByVal A As Integer, ByVal b As Integer) As Integer Implements Imyshow.add, Imyshow2.add
Ivalue = a + b
System.Console.WriteLine ("{0}+{1}={2}", A, B, Ivalue)
End Function
End Class
Public Class Common
Public Shared Sub Main ()
Dim obj as Mycls = New mycls
Dim obj2 as Imyshow = New mycls
Dim obj3 as IMyShow2 = New mycls
System.Console.WriteLine ("Class mycls Object")
Obj. Show2 ()
Obj. ADD2 (5, 4)
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.