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

Bài giảng Lập trình C# 2010: Chương 5 - ĐH Công nghệ Đồng Nai

22 10 0

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 22
Dung lượng 333,78 KB

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

Nội dung

Bài giảng Lập trình C# 2010: Chương 5 - String Class có nội dung trình bày về: Constructor, String Field, String Operators, String Methods, DEMO String & Dictionary.

Trang 3

Abstraction Encapsulation

Inheritance

Polymorphism

Trang 6

private protected

public

Trang 7

from an existing class

• The existing class is called the

• The inherited class is called the

derived , subclass , or child

relationship with its base class

Trang 8

Inheritance

Trang 9

• Inheritance supports reusability

• Reusability – creation of object

functionality that may be used in multiple projects

Trang 10

• Methods with identical names have

different implementations

• The Select method is different for radio

buttons, check boxes, and list boxes

• Allows a single class to have more than

one method with different argument lists

Trang 11

How to create Class

Trang 13

get { return this m _strID ; }

set { this m _strID = value; }

}

public string N am e

{

get { return this m _strN am e; }

set { this m _strN am e = value; }

}

public string D escription

{

get { return this m _strD escription; }

set { this m _strD escription = value; }

}

public abstract void doSom ething();

Constructor

Trang 14

get { return this m _dPrice; }

set { this m _dPrice = value ; }

Trang 15

private string m _strISBN ;

private string m _strAuthor;

private string m _strTitle;

get { return this.m _strISBN ; }

set { this.m _strISBN = value; }

}

public string Author

{

get { return this.m _strAuthor; }

set { this.m _strAuthor = value; }

}

public string Title

{

get { return this.m _strTitle; }

set { this.m _strTitle = value; }

}

}

Trang 16

{

private string m _strArtist;

private string m _strTitle;

public CCom pactD isc()

{ }

public string Artist

{

get { return this.m _strArtist; }

set { this.m _strArtist = value; }

}

public string Title

{

get { return this.m _strTitle; }

set { this.m _strTitle = value; }

Trang 17

public class CTravelG uide : CBook

{

private string m _strCountry;

public CTravelG uide()

{ }

public string Country

{

get { return this m _strCountry; }

set { this m _strCountry = value ; }

}

}

Trang 18

Garbage Collection

Trang 19

• Operator new allocates memory

• When objects are no longer referenced , the

CLR performs garbage collection

• Garbage collection helps avoid memory leaks

(running out of memory because unused

memory has not been reclaimed)

• Allocation and deallocation of other resources

(database connections, file access, etc.) must be explicitly handled by programmers

Trang 20

• Use finalizers in conjunction with the garbage collector to release resources and memory

• Before garbage collector reclaims an object’s

memory, it calls the object’s finalizer

• Each class has only one finalizer (also called

destructor )

• Name of a destructor is the ~ character ,

followed by the class name

• Destructors do not receive any arguments

Trang 21

public class CTravelG uide: CBook

{

private string m _strCountry;

public CTravelG uide()

{ }

public string Country

{

get { return this m _strCountry; }

set { this m _strCountry = value ; }

Trang 22

END

Ngày đăng: 08/05/2021, 12:17

🧩 Sản phẩm bạn có thể quan tâm