1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Indexers in Interfaces pdf

2 211 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Indexers in Interfaces
Thể loại Document
Định dạng
Số trang 2
Dung lượng 7,45 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Indexers in Interfaces You can declare indexers in an interface.. To do this, specify the get and/or set keyword, but replace the body of the get or set accessor with a semicolon.. Any c

Trang 1

Indexers in Interfaces

You can declare indexers in an interface To do this, specify the get and/or set keyword, but replace the body of the get or set accessor with a semicolon Any class or struct that implements the interface must implement the indexer accessors declared in the interface For example:

interface IRawInt

{

bool this [ int index ] { get; set; }

}

struct RawInt : IRawInt

{

public bool this [ int index ]

{

get { }

set { }

}

}

If you implement the interface indexer in a class, you can declare the indexer

implementations as virtual This allows further derived classes to override the get and set accessors For example:

class RawInt : IRawInt

{

public virtual bool this [ int index ]

{

get { }

set { }

}

}

You can also choose to implement an indexer by using the explicit interface

implementation syntax covered in Chapter 12, “Working with Inheritance.” An explicit

Trang 2

implementation of an indexer is non-public and non-virtual (and so cannot be overridden) For example:

struct RawInt : IRawInt

{

bool IRawInt.this [ int index ]

{

get { }

set { }

}

}

Ngày đăng: 26/01/2014, 13:20

TỪ KHÓA LIÊN QUAN

w