C # after-school mini-Test 4

Source: Internet
Author: User

Interfaces (interface)

In this course, we mainly learn about the features and use of interfaces in C #. In my opinion, interfaces are very much like abstract classes but different, or excuses are an escalation of abstract classes.

The main difference between interface and abstract class: interface can be placed anywhere in the program layer, and the abstract class can only be placed at the top. 、

declaring interfaces:

public interface Istorable

{

void Read ();

void Write (object);

}

Using interfaces:

public class Document:istorable

{

public void Read () {...}

public void Write (object obj) {...}

// ...

}

As we can see, the interface only writes function signatures when declaring, and cannot be implemented. When using an interface, all functions in the interface need to be implemented in the corresponding class, or the compiler will make an error.

It is important to note that multiple interfaces can be inherited at the same time

public class document:istorable, icompressible

Also, interfaces can be inherited directly, meaning that interfaces can be combined.

public interface C:a,b (where A,b,c is the interface name)

{

......

}

Description of the keyword as: A as B, the left operand is converted to the right operand, and if B is an interface of a, it can be converted. No, the null value is returned.

Array

Statement: type [] arry-name;

Keyword params

When used, it is placed before the parameters of the function definition.

public void Displayvals (params int[] intvals)

{...; }

When you call this function, you can write an array of items without writing the array in parentheses.

C # after-school mini-Test 4

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.