...C09. Array, Indexers and Collections.pdf

19 84 0
...C09. Array, Indexers and Collections.pdf

Đ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

...C09. Array, Indexers and Collections.pdf tài liệu, giáo án, bài giảng , luận văn, luận án, đồ án, bài tập lớn về tất...

Au0586 half title page 11/17/05 2:05 PM Page 1 EMBEDDEDLINUX SYSTEMDESIGN ANDDEVELOPMENT TEAM FLYAu0586 title page 11/17/05 2:04 PM Page 1 Boca Raton New YorkEMBEDDEDLINUX SYSTEMDESIGN ANDDEVELOPMENTP. Raghavan • Amol Lad • Sriram Neelakandan Published in 2006 byAuerbach Publications Taylor & Francis Group 6000 Broken Sound Parkway NW, Suite 300Boca Raton, FL 33487-2742© 2006 by Taylor & Francis Group, LLCAuerbach is an imprint of Taylor & Francis GroupNo claim to original U.S. Government worksPrinted in the United States of America on acid-free paper10987654321International Standard Book Number-10: 0-8493-4058-6 (Hardcover) International Standard Book Number-13: 978-0-8493-4058-1 (Hardcover) Library of Congress Card Number 2005048179This book contains information obtained from authentic and highly regarded sources. Reprinted material is quoted withpermission, and sources are indicated. A wide variety of references are listed. Reasonable efforts have been made to publishreliable data and information, but the author and the publisher cannot assume responsibility for the validity of all materialsor for the consequences of their use.No part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, orother means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any informationstorage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, please access www.copyright.com(http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC) 222 Rosewood Drive, Danvers, MA01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. Fororganizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged.Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only foridentification and explanation without intent to infringe.Library of Congress Cataloging-in-Publication DataRaghavan, P. (Pichai), 1973-embedded linux system design and development pdf' title='embedded linux system design and development pdf'>Embedded Linux System Design and Development Ⅲ Borland is a registered trademark of Borland Software Corporation in the United States and other countries. Ⅲ Merant is a registered trademark of Merant. Ⅲ SnapGear is a registered trademark of SnapGear Inc. Ⅲ Matsushita is a trademark of the Matsushita Electric Corporation. Ⅲ I2C is a trademark of Philips Semiconductors Corporation. Ⅲ Philips® is a registered trademark of Philips Consumer Electronics Corporation. Ⅲ Cadenux is a trademark of Cadenux, LLC. Ⅲ ELinOS is a registered trademark of SYSGO AG. Ⅲ Metrowerks and CodeWarrior are trademarks of Metrowerks Corp. in the U.S. or other countries. Ⅲ FreeBSD is a registered trademark of the FreeBSD Foundation. Ⅲ IEEE and POSIX are registered trademarks of Institute of Electrical and Electronics Engineers, Inc. in the United States. Ⅲ Xtensa is a trademark belonging to Tensilica Inc. Ⅲ Fujitsu is a registered trademark of Fujitsu, Ltd. Ⅲ Firewire is a registered trademark of Apple computer. Ⅲ SuperH is a trademark of Hitachi, Ltd. Ⅲ Windows, WinCE and Microsoft are registered trademarks and MS-DOS and DirectX .are trademarks of Microsoft Corporation. Ⅲ Solaris and Java are registered trademarks and N gôn ngữ C # T rần V ăn T èo tvteo@agu.edu.vn 01/06/2006 N g ôn n g ữ C # Arrays, Indexers and Collections n n n n M ản g (A rray) C âu lệnh foreach Indexers G iao diện C ollection 01/06/2006 N g ôn n g ữ C # M ảng (A rray) n n n H o ạt động tư ng tự m ảng C /C + + T u y n h iên m ảng C # đối tư ợ ng, nghĩa kiểu q u i ch iếu đư ợ c dẫn x u ất từ lớ p sở System.Array C ác loại m ảng: m ột chiều, nhiều chiều, răn g cư a T rư c sử dụng m ảng phải thự c b c sau : • K hai báo m ảng • T hể m ảng • K hở i gán phần tử 01/06/2006 N g ôn n g ữ C # M ảng m ột chiều n Cú pháp: type type[] [] array array name name;; int[] intArray; //khao báo intArray = new int[5]; //T h ể b iện H oặc int[] intArray = new int[5]; n K h i gán m ảng lúc khai báo int[] intArray = {120, 50, 30, 10}; H oặc int[] intArray = new int[5]{120, 50, 30, 10}; H oặc int[] intArray = new int[]{120, 50, 30, 10}; Sai  int [] intArray; intArray = {120, 50, 30, 10}; 01/06/2006 N g ôn n g ữ C # M ảng m ột chiều T ìm hiểu trị m ặc n h iên : int[] intArray = new int[5]; Button[] btnArray = new Button[3]; • • • • 01/06/2006 intArray m ột m ảng gồm số ngu yên, đư ợ c gán zero zero,, trị m ặc nhiên kiểu số nguyên intArray kiểu qui chiếu, ng phần tử (intArray[0], intArray[1]… intArray[1]… ) thuộc kiểu trị theo kiểu số nguyên btnArray m ột m ảng gồm phần tử vớ i null reference reference Button kiểu qui chiếu N hư ng câu lệnh không tạo phần tử qui chiếu đối tư ợ ng Button Button N g ôn n g ữ C # M ảng m ột chiều C âu lệnh foreach foreach:: n n Cú pháp: foreach (type identifier in expresstion) statement D uyệt qua tất phần tử m ảng (array) hay tập hợ p (collection), xem xét từ ng phần tử public class Employee{ int [] arrInt = new int [3]; public Employee( int empID ) { foreach ( int i in arrInt ) … } Employee[] arrEmp =new Employee[3]; public override string ToString( ){ for( int i = ; i < arrEmp.Length ; i++ ) } private int empID; }01/06/2006 arrEmp[i] = new Employee ( i ); foreach ( Employee emp in arrEmp ) // T hự c h iện vớ i từ ng ph ần tử N g ôn n g ữ C # M ảng m ột chiều T rao m ảng m ộ t th am số : n C ó thể truyền m ột m ảng khở i gán cho hàm : int[] arrInt = new int[3] { , , }; n C ó thể vừ a khở i gán vừ a truyền cho hàm T k h ó a params params:: n Temp.MyFunc( arrInt ); Temp.MyFunc( new int[3] { , , } ); public void Func( params int[] intVals) C ho phép đư a vào m ột số thông số m khôn g cần phải rõ ràng, không cần tư ng m inh, không cần m ảng Temp.Func( 4,8,5,7) H oặc 01/06/2006 int[] arr = new int[5]{5,8,3,6,4}; N g ôn n g ữ C # Temp.Func( arr ); M ảng nhiều chiều n Cú pháp: type[ , ] arrayarray-n am e; //h chiều type[ , , ]array]array-nam e; //ba chiều int[,] intArray = new int[2,3]; //M ản g có dò ng cộ t H oặc int[,] intArray = new int[,] { {2,3,4,5}, {4,5,6,7}, {6,7,8,9} }; H oặc int[,,] intArray; intArray = new int[,,]{ {{2,3},{3,4},{4,5}}, {{6,7},{7,8},{8,9}} }; n S d ụng phần tử m ảng intArray[0,0] = 5; intArray[0,1] = 10; intArray[0][0] = 5; intArray[0][1] = 10; 01/06/2006 N g ôn n g ữ C # M ảng nhiều chiều n Cú pháp: type[ , ] arrayarray-n am e; //h chiều type[ , , ]array]array-nam e; //ba chiều int[,] intArray = new int[2,3]; //M ản g có dò ng cộ t H oặc int[,] intArray = new int[,] { {2,3,4,5}, {4,5,6,7}, {6,7,8,9} }; H oặc int[,,] intArray; intArray = new int[,,]{ {{2,3},{3,4},{4,5}}, {{6,7},{7,8},{8,9}} }; n S d ụng phần tử m ảng intArray[0,0] = 5; intArray[0,1] = 10; intArray[0][0] = 5; intArray[0][1] = 10; 01/06/2006 N g ôn n g ữ C # M ảng lở m chở m (Jagged A rray) n n L m ột m ảng m m ỗ i p h ần tử lại m ộ t m ản g , v i k ích thư c khác Cú pháp: type[][] arrayarray-name; int[][] intArray = new int[3][]; intArray[0] = new int[3]; intArray[1] = new int[2]; intArray[2] = new int[5]; int[][] intArray = new int[][] { new int[]{ , , }, new int[]{ , } } int[][,] intArray = new int[2][,] { new int[,]{ {2 , 5} , {3, 4} } , new int[,]{ (2 , 4},{4, 6} } } 01/06/2006 N g ôn n g ữ C # 10 L p sở S ystem A rray n M ỗ i m ảng đư ợ c tạo đ ều tự đ ộ n g đ ợ c d ẫn x u ất từ lớ p S ystem A rray, vớ i hàm thu ộc tín h g iú p bạn thao tác m ảng • T huộc tính Length: trả số phần tử tất chiểu m ảng • T huộc tính Rank: trả số chiều m ảng • Hàm GetLength: trả số phần tử m ột chiều đư ợ c định • Hàm Reverse Reverse:: đảo ngư ợ c m ảng • Hàm Sort Sort:: xếp m ảng • … … … … 01/06/2006 N g ôn n g ữ C # 11 B ộ m ục (Indexer) n n n T ru y xuất nhữ ng tập h ợ p n ằm tro n g m ột lớ p S d ụng cho nhữ ng lớ p có c giốn g m ản g h ay tập h ợ p L m ột thuộc tính public class MyListBox{ MyListBox lst = private string[] myString; new MyListBox( ); //Lay mot phan tu string str = lst.layPhantu(2); public string layPhantu(int i) { MyListBox lst = return myString[i]; new MyListBox( ); } str = lst[2]; } //End MyListBox 01/06/2006 N g ôn n g ữstring C# 12 B ộ m ục (Indexer) n Khai báo: type this this[[type argument]{ argument]{ get;set; } public class MyListBox{ private string[] myString; public string this [int index]{ get{ return myString [index ];} set{ myString ... CHECK YOUR ENGLISH VOCABULARY FORBUSINESSADMINISTRATIONRawdon WyattANDA & C Black Ⴇ London4th edition www.acblack.comFirst published as Check Your Vocabulary for Business in 1996 by Peter Collin PublishingSecond edition published 1999Third edition published 2003by Bloomsbury Publishing PlcThis fourth edition published 2007 byA & C Black Publishers Ltd38 Soho Square, London W1D 3HB© Rawdon Wyatt 2007All rights reserved.No part of this publication may be reproduced inany form without the permission of the publishers.A CIP entry for this book is available from the British LibraryISBN-10: 0-7136-7916-6ISBN-13: 978-0-7136-7916-8 eISBN-13: 978-1-4081-0251-0Text typeset by A & C BlackPrinted in Great Britain at Caligraving Ltd, Thetford, NorfolkThis book is produced using paper that is made from wood grown in managed, sustainable forests. It is natural, renewable andrecyclable. The logging and manufacturing processes conform to the environmental regulations of the country of origin. If you want to practise and develop your knowledge of English vocabulary for Business andAdministration, you will find that the exercises in this book will help you. They areparticularly useful if:If you want to make the most of the exercises in the book, you should note the following:We hope that you enjoy doing the exercises in this book, and that they help you to practiseand develop the Business and Administration vocabulary that you need.Introduction¼You work, or are planning to work, in or around an English-speaking business environment.¼Your work brings you into regular contact with English-speaking business people.¼You are planning to take a Business English examination such as BEC Vantage /Higher, TOEIC, or one of the LCCI (London Chamber of Commerce and Industry) International Qualifications, especially 2nd, 3rdor 4thlevel Business.¼You do not work directly in Business and Administration, but your job requires you to have a working knowledge of common business words and expressions.¼This is not a course book, and you do not need to work through it 'mechanically' from beginning to end. It is better to choose areas that you are unfamiliar with, or areas that you feel are of specific interest or importance to you.¼Write down new words and expressions that you learn. Develop your own personal vocabulary 'bank' in a notebook or file. Review these words and expressions on a regular basis so that they become a part of your 'productive' vocabulary.¼Use a good general-English dictionary and a good business-English dictionary to check the meanings of new words and expressions (but try to do the exercises first before looking in the dictionary). Many of the examples in this book have been taken from the Macmillan English Dictionary (ISBN 978-0-333-96847-5) and the A&C Black Dictionary of Business 4thedition (ISBN 978-0-713-67918-2).¼The exercises in this book either focus on general business vocabulary (for example, phrasal verbs, formal words, words with similar meanings, etc) or topic-specific business vocabulary (for example, sales CHECK YOUR ENGLISH VOCABULARY FORPHRASAL VERBSIDIOMSRawdon WyattANDA & C Black Ⴇ London www.acblack.comFirst published in Great Britain 2006A & C Black Publishers Ltd38 Soho Square, London W1D 3HB© Rawdon Wyatt 2006All rights reserved.No part of this publication may be reproduced inany form without the permission of the publishers.A CIP entry for this book is available from the British LibraryISBN-10: 0 7136 7805 4ISBN-13: 978 0 7136 7805 5 eISBN-13: 978-1-4081-0158-2Text typeset by A & C BlackPrinted in Great Britain at Caligraving Ltd, Thetford, NorfolkThis book is produced using paper that is made from wood grown in managed, sustainable forests. It is natural, renewable andrecyclable. The logging and manufacturing processes conform to the environmental regulations of the country of origin. If you want to practise and develop your knowledge of phrasal verbs and idioms, you will find this book veryuseful. The various exercises contain many of the most common phrasal verbs and idioms, together withsome useful spoken expressions that you might expect to hear or use in an English-speaking environment.You should not go through this book mechanically from beginning to end. It is better to choose oneparticular verb or topic, do the exercise(s), make a record of any new words and expressions that you learn,then practise using these in sentences or situations of your own. When you feel you have a good commandof these, move to another verb or topic and do the same. You should also review the things you have learnedon a regular basis, so that they remain 'fresh' in your mind and become part of your 'active' vocabulary.The meanings of most of the phrasal verbs and idioms are explained in the book, either in the exercisesthemselves, or in the answer key at the back. This key also provides you with lots of similar or alternativeexpressions, together with examples of how they are used. However, we recommend that you keep a gooddictionary with you, and refer to it when necessary. In particular, we recommend the A & C Black EasierEnglish Intermediate Dictionary (ISBN 0-7475-6989-4) or the Macmillan English Dictionary (ISBN 0-333-96482-9), from which many of the definitions and sample sentences in this book have been taken.No vocabulary book can possibly contain all of the thousands of English phrasal verbs and idioms that you arelikely to come across or need, so it is important to acquire new ones from other sources. If you have accessto English-language newspapers, popular magazines, television and radio programmes, films and albums ofpopular music, you will find that these are excellent resources.We hope that you enjoy doing the exercises in this book. Before you begin, we suggest that you read thisimportant information about phrasal verbs and idioms.What is a phrasal verb?A phrasal verb is a verb formed from two (or sometimes three) parts: a verb and an adverb or preposition.These adverbs and Contents Overview 1 Strings 2 Terminology – Collections 20 .NET Framework Arrays 21 .NET Framework Collections 39 Lab 7: Working with Strings, Enumerators, and Collections 57 Review 63 Module 7: Strings, Arrays, and Collections Information in this document, including URL and other Internet Web site references, is subject to change without notice. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, place or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property.  2001-2002 Microsoft Corporation. All rights reserved. Microsoft, ActiveX, BizTalk, IntelliMirror, Jscript, MSDN, MS-DOS, MSN, PowerPoint, Visual Basic, Visual C++, Visual C#, Visual Studio, Win32, Windows, Windows Media, and Window NT are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners. Module 7: Strings, Arrays, and Collections iii Instructor Notes After completing this module, students will be able to: ! Parse, format, manipulate, and compare strings. ! Use the classes in the System.Array and System.Collections namespaces. ! Improve the type safety and performance of collections by using specialized collections and class-specific code. Materials and Preparation This section provides the materials and preparation tasks that you need to teach this module. Required Materials To teach this module, you need the Microsoft ® PowerPoint ® file 2349B_07.ppt. Preparation Tasks To prepare for this module, you should: ! Read all of the materials for this module. ! Practice the demonstrations. ! Complete the lab. Presentation: 120 Minutes Lab: 60 Minutes iv Module 7: Strings, Arrays, and Collections Demonstrations This section provides demonstration procedures that will not fit in the margin notes or are not appropriate for the student notes. Sorting and Enumerating an Array In this demonstration, you will show students how to sort and enumerate an array. The code for this demonstration is contained in one project and is located in <install folder>\Democode\Mod07\Demo07.1. In addition, the code for the individual demonstration is provided in the student notes. ArrayList In this demonstration, you will show students how ArrayList implements the IList interface by using an array whose size is dynamically increased as required. The code for this demonstration is contained in one project and is located in <install folder>\Democode\Mod07\Demo07.2. In addition, the code for the individual demonstration is provided in the student notes. Hashtable In this demonstration, you will show students how to create a hash table that is used for searches. The code ...Arrays, Indexers and Collections n n n n M ản g (A rray) C âu lệnh foreach Indexers G iao diện C ollection 01/06/2006 N g ôn n g ữ C # M

Ngày đăng: 05/11/2017, 03:41

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan