Download as pdf or txt
Download as pdf or txt
You are on page 1of 49

Download and Read online, DOWNLOAD EBOOK, [PDF EBOOK EPUB ], Ebooks

download, Read Ebook EPUB/KINDE, Download Book Format PDF

Interactive C#: Fundamentals, Core Concepts and


Patterns 1st Edition Vaskaran Sarcar

OR CLICK LINK
https://textbookfull.com/product/interactive-c-
fundamentals-core-concepts-and-patterns-1st-
edition-vaskaran-sarcar/

Read with Our Free App Audiobook Free Format PFD EBook, Ebooks dowload PDF
with Andible trial, Real book, online, KINDLE , Download[PDF] and Read and Read
Read book Format PDF Ebook, Dowload online, Read book Format PDF Ebook,
[PDF] and Real ONLINE Dowload [PDF] and Real ONLINE
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Java Design Patterns A tour of 23 gang of four design


patterns in Java 1st Edition Vaskaran Sarcar

https://textbookfull.com/product/java-design-patterns-a-tour-
of-23-gang-of-four-design-patterns-in-java-1st-edition-vaskaran-
sarcar/

Java design patterns a tour of 23 gang of four design


patterns in Java 1st Edition Vaskaran Sarcar

https://textbookfull.com/product/java-design-patterns-a-tour-
of-23-gang-of-four-design-patterns-in-java-1st-edition-vaskaran-
sarcar-2/

Getting Started with Advanced C# 1st Edition Vaskaran


Sarcar [Sarcar

https://textbookfull.com/product/getting-started-with-
advanced-c-1st-edition-vaskaran-sarcar-sarcar/

Design Patterns in C#: A Hands-on Guide with Real-world


Examples 2nd Edition Vaskaran Sarcar

https://textbookfull.com/product/design-patterns-in-c-a-hands-on-
guide-with-real-world-examples-2nd-edition-vaskaran-sarcar/
Java Design Patterns: A Hands-On Experience with Real-
World Examples 2nd Edition Vaskaran Sarcar

https://textbookfull.com/product/java-design-patterns-a-hands-on-
experience-with-real-world-examples-2nd-edition-vaskaran-sarcar/

Biota Grow 2C gather 2C cook Loucas

https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-
loucas/

Functional and Concurrent Programming Core Concepts and


Features 1st Edition Charpentier

https://textbookfull.com/product/functional-and-concurrent-
programming-core-concepts-and-features-1st-edition-charpentier/

Psychology: Core Concepts Philip G. Zimbardo

https://textbookfull.com/product/psychology-core-concepts-philip-
g-zimbardo/

Design Patterns in .NET Core 3: Reusable Approaches in


C# and F# for Object-Oriented Software Design 2nd
Edition Dmitri Nesteruk

https://textbookfull.com/product/design-patterns-in-net-
core-3-reusable-approaches-in-c-and-f-for-object-oriented-
software-design-2nd-edition-dmitri-nesteruk/
Interactive
C#
Fundamentals, Core Concepts and Patterns

Vaskaran Sarcar
Foreword by A. Rajendram and S. Ghosh
Interactive C#
Fundamentals, Core Concepts
and Patterns

Vaskaran Sarcar
Foreword by A. Rajendram and S. Ghosh
Interactive C#
Vaskaran Sarcar
560066, Karnataka, India

ISBN-13 (pbk): 978-1-4842-3338-2 ISBN-13 (electronic): 978-1-4842-3339-9


https://doi.org/10.1007/978-1-4842-3339-9
Library of Congress Control Number: 2017962428

Copyright © 2018 by Vaskaran Sarcar


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Cover image designed by Freepik (www.freepik.com)
Managing Director: Welmoed Spahr
Editorial Director: Todd Green
Acquisitions Editor: Celestin Suresh John
Development Editor: Matthew Moodie
Technical Reviewer: Shekhar Kumar Maravi
Coordinating Editor: Sanchita Mandal
Copy Editor: Kim Burton-Weisman
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street,
6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-
sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member
(owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a
Delaware corporation.
For information on translations, please e-mail rights@apress.com, or visit http://www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/978-1-4842-3338-2. For more
detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
Table of Contents
Foreword by Ambrose Rajendram������������������������������������������������������������������������xxiii

Foreword by Siddhartha Ghosh�����������������������������������������������������������������������������xxv


About the Author�������������������������������������������������������������������������������������������������xxvii

About the Technical Reviewers����������������������������������������������������������������������������xxix

Acknowledgements����������������������������������������������������������������������������������������������xxxi

Preface���������������������������������������������������������������������������������������������������������������xxxiii

Guidelines for Using the Book���������������������������������������������������������������������������xxxvii

Part I: Enter into the World of OOP�������������������������������������������������������� 1


Chapter 1: Object-Oriented Programming Concepts������������������������������������������������ 3
Class and Objects������������������������������������������������������������������������������������������������������������������������� 5
Encapsulation������������������������������������������������������������������������������������������������������������������������������� 6
Abstraction������������������������������������������������������������������������������������������������������������������������������������ 6
Inheritance������������������������������������������������������������������������������������������������������������������������������������ 7
Polymorphism������������������������������������������������������������������������������������������������������������������������������� 7
Summary�������������������������������������������������������������������������������������������������������������������������������������� 9

Chapter 2: The Building Blocks: Class and Objects������������������������������������������������ 11


Class������������������������������������������������������������������������������������������������������������������������������������������� 11
Object������������������������������������������������������������������������������������������������������������������������������������������ 11
Class Demonstrations����������������������������������������������������������������������������������������������������������������� 15
Demonstration 1������������������������������������������������������������������������������������������������������������������������� 16
Output������������������������������������������������������������������������������������������������������������������������������������ 17
Additional Comments������������������������������������������������������������������������������������������������������������ 17

iii
Table of Contents

Demonstration 2������������������������������������������������������������������������������������������������������������������������� 19
Output������������������������������������������������������������������������������������������������������������������������������������ 20
Analysis��������������������������������������������������������������������������������������������������������������������������������� 20
Additional Comments������������������������������������������������������������������������������������������������������������ 21
Quiz��������������������������������������������������������������������������������������������������������������������������������������� 23
Output������������������������������������������������������������������������������������������������������������������������������������ 23
Explanation���������������������������������������������������������������������������������������������������������������������������� 24
Demonstration 3������������������������������������������������������������������������������������������������������������������������� 27
Output������������������������������������������������������������������������������������������������������������������������������������ 28
Explanation���������������������������������������������������������������������������������������������������������������������������� 28
Demonstration 4������������������������������������������������������������������������������������������������������������������������� 30
Output������������������������������������������������������������������������������������������������������������������������������������ 31
Additional Comments������������������������������������������������������������������������������������������������������������ 31
Demonstration 5������������������������������������������������������������������������������������������������������������������������� 31
Output������������������������������������������������������������������������������������������������������������������������������������ 32
Object Initializers������������������������������������������������������������������������������������������������������������������������ 33
Demonstration 6������������������������������������������������������������������������������������������������������������������������� 33
Output������������������������������������������������������������������������������������������������������������������������������������ 34
Analysis��������������������������������������������������������������������������������������������������������������������������������� 35
Optional Parameters������������������������������������������������������������������������������������������������������������������� 35
Demonstration 7������������������������������������������������������������������������������������������������������������������������� 36
Output������������������������������������������������������������������������������������������������������������������������������������ 37
Analysis��������������������������������������������������������������������������������������������������������������������������������� 37
Summary������������������������������������������������������������������������������������������������������������������������������������ 39

Chapter 3: The Concept of Inheritance������������������������������������������������������������������� 41


Types������������������������������������������������������������������������������������������������������������������������������������������� 41
Demonstration 1������������������������������������������������������������������������������������������������������������������������� 44
Output������������������������������������������������������������������������������������������������������������������������������������ 44
Additional Comments������������������������������������������������������������������������������������������������������������ 45

iv
Table of Contents

Demonstration 2������������������������������������������������������������������������������������������������������������������������� 46
Output������������������������������������������������������������������������������������������������������������������������������������ 46
Analysis��������������������������������������������������������������������������������������������������������������������������������� 47
Demonstration 3������������������������������������������������������������������������������������������������������������������������� 47
Demonstration 4������������������������������������������������������������������������������������������������������������������������� 50
Output������������������������������������������������������������������������������������������������������������������������������������ 51
Explanation���������������������������������������������������������������������������������������������������������������������������� 51
A Special Keyword: base������������������������������������������������������������������������������������������������������������� 52
Demonstration 5������������������������������������������������������������������������������������������������������������������������� 52
Output������������������������������������������������������������������������������������������������������������������������������������ 53
Analysis��������������������������������������������������������������������������������������������������������������������������������� 54
Quiz��������������������������������������������������������������������������������������������������������������������������������������� 55
Output������������������������������������������������������������������������������������������������������������������������������������ 55
Analysis��������������������������������������������������������������������������������������������������������������������������������� 56
Demonstration 6������������������������������������������������������������������������������������������������������������������������� 56
Output������������������������������������������������������������������������������������������������������������������������������������ 57
Demonstration 7������������������������������������������������������������������������������������������������������������������������� 58
Output������������������������������������������������������������������������������������������������������������������������������������ 59
Analysis��������������������������������������������������������������������������������������������������������������������������������� 59
Summary������������������������������������������������������������������������������������������������������������������������������������ 62

Chapter 4: Get Familiar with Polymorphism����������������������������������������������������������� 63


Method Overloading�������������������������������������������������������������������������������������������������������������������� 63
Demonstration 1������������������������������������������������������������������������������������������������������������������������� 64
Output������������������������������������������������������������������������������������������������������������������������������������ 65
Analysis��������������������������������������������������������������������������������������������������������������������������������� 65
Quiz��������������������������������������������������������������������������������������������������������������������������������������� 65
Answer���������������������������������������������������������������������������������������������������������������������������������� 66
Quiz��������������������������������������������������������������������������������������������������������������������������������������� 66
Answer���������������������������������������������������������������������������������������������������������������������������������� 66

v
Table of Contents

Demonstration 2������������������������������������������������������������������������������������������������������������������������� 67
Output������������������������������������������������������������������������������������������������������������������������������������ 68
Analysis��������������������������������������������������������������������������������������������������������������������������������� 68
Demonstration 3������������������������������������������������������������������������������������������������������������������������� 68
Output������������������������������������������������������������������������������������������������������������������������������������ 69
Demonstration 4������������������������������������������������������������������������������������������������������������������������� 69
Output������������������������������������������������������������������������������������������������������������������������������������ 70
Analysis��������������������������������������������������������������������������������������������������������������������������������� 70
Quiz��������������������������������������������������������������������������������������������������������������������������������������� 72
Demonstration 5������������������������������������������������������������������������������������������������������������������������� 72
A Suggestion/Good Programming Practice��������������������������������������������������������������������������� 73
Operator Overloading������������������������������������������������������������������������������������������������������������������ 74
Demonstration 6������������������������������������������������������������������������������������������������������������������������� 75
Output������������������������������������������������������������������������������������������������������������������������������������ 76
Demonstration 7������������������������������������������������������������������������������������������������������������������������� 77
Output������������������������������������������������������������������������������������������������������������������������������������ 78
Analysis��������������������������������������������������������������������������������������������������������������������������������� 79
Method Overriding���������������������������������������������������������������������������������������������������������������������� 80
Demonstration 8������������������������������������������������������������������������������������������������������������������������� 80
Output������������������������������������������������������������������������������������������������������������������������������������ 81
Analysis��������������������������������������������������������������������������������������������������������������������������������� 81
Demonstration 9������������������������������������������������������������������������������������������������������������������������� 83
Output������������������������������������������������������������������������������������������������������������������������������������ 84
Demonstration 10����������������������������������������������������������������������������������������������������������������������� 85
Output������������������������������������������������������������������������������������������������������������������������������������ 86
Experiment with Polymorphism�������������������������������������������������������������������������������������������������� 86
Demonstration 11����������������������������������������������������������������������������������������������������������������������� 86
Output������������������������������������������������������������������������������������������������������������������������������������ 88
Analysis��������������������������������������������������������������������������������������������������������������������������������� 88

vi
Table of Contents

Demonstration 12����������������������������������������������������������������������������������������������������������������������� 89
Output������������������������������������������������������������������������������������������������������������������������������������ 90
Analysis��������������������������������������������������������������������������������������������������������������������������������� 90
Demonstration 13����������������������������������������������������������������������������������������������������������������������� 92
Output������������������������������������������������������������������������������������������������������������������������������������ 94
Explanation���������������������������������������������������������������������������������������������������������������������������� 94
Demonstration 14����������������������������������������������������������������������������������������������������������������������� 95
Output������������������������������������������������������������������������������������������������������������������������������������ 95
Demonstration 15����������������������������������������������������������������������������������������������������������������������� 95
Output������������������������������������������������������������������������������������������������������������������������������������ 96
Demonstration 16����������������������������������������������������������������������������������������������������������������������� 97
Output������������������������������������������������������������������������������������������������������������������������������������ 97
Quiz��������������������������������������������������������������������������������������������������������������������������������������� 97
Demonstration 17����������������������������������������������������������������������������������������������������������������������� 98
Output������������������������������������������������������������������������������������������������������������������������������������ 99
Explanation���������������������������������������������������������������������������������������������������������������������������� 99
Quiz������������������������������������������������������������������������������������������������������������������������������������� 100
Answer�������������������������������������������������������������������������������������������������������������������������������� 100
Quiz������������������������������������������������������������������������������������������������������������������������������������� 100
Answer�������������������������������������������������������������������������������������������������������������������������������� 100
Demonstration 18��������������������������������������������������������������������������������������������������������������������� 101
Output���������������������������������������������������������������������������������������������������������������������������������� 102
Analysis������������������������������������������������������������������������������������������������������������������������������� 103
Demonstration 19��������������������������������������������������������������������������������������������������������������������� 103
Output���������������������������������������������������������������������������������������������������������������������������������� 105
Demonstration 20��������������������������������������������������������������������������������������������������������������������� 106
Output���������������������������������������������������������������������������������������������������������������������������������� 107
Analysis������������������������������������������������������������������������������������������������������������������������������� 107
Demonstration 21��������������������������������������������������������������������������������������������������������������������� 108
Output���������������������������������������������������������������������������������������������������������������������������������� 109
Analysis������������������������������������������������������������������������������������������������������������������������������� 109

vii
Table of Contents

Abstract Class��������������������������������������������������������������������������������������������������������������������������� 110


Demonstration 22��������������������������������������������������������������������������������������������������������������������� 110
Output���������������������������������������������������������������������������������������������������������������������������������� 111
Demonstration 23��������������������������������������������������������������������������������������������������������������������� 112
Output���������������������������������������������������������������������������������������������������������������������������������� 113
Explanation�������������������������������������������������������������������������������������������������������������������������� 114
Quiz������������������������������������������������������������������������������������������������������������������������������������� 115
Answer�������������������������������������������������������������������������������������������������������������������������������� 115
Quiz������������������������������������������������������������������������������������������������������������������������������������� 118
Output���������������������������������������������������������������������������������������������������������������������������������� 119
Quiz������������������������������������������������������������������������������������������������������������������������������������� 119
Output���������������������������������������������������������������������������������������������������������������������������������� 120
Summary���������������������������������������������������������������������������������������������������������������������������������� 122

Chapter 5: Interfaces: An Art in OOP�������������������������������������������������������������������� 123


Introduction to Interfaces���������������������������������������������������������������������������������������������������������� 123
Demonstration 1����������������������������������������������������������������������������������������������������������������������� 124
Output���������������������������������������������������������������������������������������������������������������������������������� 125
Analysis������������������������������������������������������������������������������������������������������������������������������� 126
Demonstration 2����������������������������������������������������������������������������������������������������������������������� 126
Output���������������������������������������������������������������������������������������������������������������������������������� 128
Demonstration 3����������������������������������������������������������������������������������������������������������������������� 128
Output���������������������������������������������������������������������������������������������������������������������������������� 129
Demonstration 4����������������������������������������������������������������������������������������������������������������������� 130
Output���������������������������������������������������������������������������������������������������������������������������������� 131
Demonstration 5����������������������������������������������������������������������������������������������������������������������� 132
Output���������������������������������������������������������������������������������������������������������������������������������� 134
Quiz������������������������������������������������������������������������������������������������������������������������������������� 134
Output���������������������������������������������������������������������������������������������������������������������������������� 135
Analysis������������������������������������������������������������������������������������������������������������������������������� 135
Tag/Tagging/Marker Interface��������������������������������������������������������������������������������������������������� 136

viii
Table of Contents

Demonstration 6����������������������������������������������������������������������������������������������������������������������� 140


Output���������������������������������������������������������������������������������������������������������������������������������� 140
Demonstration 7����������������������������������������������������������������������������������������������������������������������� 141
Output���������������������������������������������������������������������������������������������������������������������������������� 141
Summary���������������������������������������������������������������������������������������������������������������������������������� 144

Chapter 6: Encapsulation with Properties and Indexers�������������������������������������� 145


Overview of Properties�������������������������������������������������������������������������������������������������������������� 145
Demonstration 1����������������������������������������������������������������������������������������������������������������������� 145
Output���������������������������������������������������������������������������������������������������������������������������������� 147
Analysis������������������������������������������������������������������������������������������������������������������������������� 147
Reduce the Code Size���������������������������������������������������������������������������������������������������������� 150
Demonstration 2����������������������������������������������������������������������������������������������������������������������� 151
IL Code��������������������������������������������������������������������������������������������������������������������������������� 152
Virtual Property������������������������������������������������������������������������������������������������������������������������� 155
Demonstration 3����������������������������������������������������������������������������������������������������������������������� 155
Output���������������������������������������������������������������������������������������������������������������������������������� 156
Abstract Property���������������������������������������������������������������������������������������������������������������������� 157
Quiz������������������������������������������������������������������������������������������������������������������������������������� 157
Output���������������������������������������������������������������������������������������������������������������������������������� 158
Analysis������������������������������������������������������������������������������������������������������������������������������� 158
Quiz������������������������������������������������������������������������������������������������������������������������������������� 158
Output���������������������������������������������������������������������������������������������������������������������������������� 159
Analysis������������������������������������������������������������������������������������������������������������������������������� 159
Indexers������������������������������������������������������������������������������������������������������������������������������������ 160
Demonstration 4����������������������������������������������������������������������������������������������������������������������� 160
Output���������������������������������������������������������������������������������������������������������������������������������� 161
Analysis������������������������������������������������������������������������������������������������������������������������������� 161
Demonstration 5����������������������������������������������������������������������������������������������������������������������� 163
Output���������������������������������������������������������������������������������������������������������������������������������� 165
Analysis������������������������������������������������������������������������������������������������������������������������������� 166
Interface Indexer����������������������������������������������������������������������������������������������������������������������� 166

ix
Table of Contents

Demonstration 6����������������������������������������������������������������������������������������������������������������������� 167


Output���������������������������������������������������������������������������������������������������������������������������������� 168
Quiz������������������������������������������������������������������������������������������������������������������������������������� 168
Answer�������������������������������������������������������������������������������������������������������������������������������� 170
Analysis������������������������������������������������������������������������������������������������������������������������������� 170
Summary���������������������������������������������������������������������������������������������������������������������������������� 172

Chapter 7: Understanding Class Variables����������������������������������������������������������� 173


Class Variables�������������������������������������������������������������������������������������������������������������������������� 173
Demonstration 1����������������������������������������������������������������������������������������������������������������������� 173
Output���������������������������������������������������������������������������������������������������������������������������������� 174
Analysis������������������������������������������������������������������������������������������������������������������������������� 174
Discussions on Static Methods������������������������������������������������������������������������������������������������� 178
Demonstration 2����������������������������������������������������������������������������������������������������������������������� 178
Output���������������������������������������������������������������������������������������������������������������������������������� 179
Demonstration 3����������������������������������������������������������������������������������������������������������������������� 180
Output���������������������������������������������������������������������������������������������������������������������������������� 181
Analysis������������������������������������������������������������������������������������������������������������������������������� 182
Discussions on Static Constructors������������������������������������������������������������������������������������������ 182
Demonstration 4����������������������������������������������������������������������������������������������������������������������� 183
Output���������������������������������������������������������������������������������������������������������������������������������� 184
Analysis������������������������������������������������������������������������������������������������������������������������������� 184
Summary���������������������������������������������������������������������������������������������������������������������������������� 186

Chapter 8: Analysis of Some Key Comparisons in C#������������������������������������������� 187


Implicit Casting vs. Explicit Casting������������������������������������������������������������������������������������������ 187
Boxing vs. UnBoxing����������������������������������������������������������������������������������������������������������������� 188
Demonstration 1����������������������������������������������������������������������������������������������������������������������� 190
Output���������������������������������������������������������������������������������������������������������������������������������� 191
Analysis������������������������������������������������������������������������������������������������������������������������������� 191

x
Table of Contents

Demonstration 2����������������������������������������������������������������������������������������������������������������������� 191


Output���������������������������������������������������������������������������������������������������������������������������������� 192
Analysis������������������������������������������������������������������������������������������������������������������������������� 193
Demonstration 3����������������������������������������������������������������������������������������������������������������������� 193
Analysis������������������������������������������������������������������������������������������������������������������������������� 194
Output���������������������������������������������������������������������������������������������������������������������������������� 194
Upcasting vs. Downcasting������������������������������������������������������������������������������������������������������� 195
Demonstration 4����������������������������������������������������������������������������������������������������������������������� 195
Output���������������������������������������������������������������������������������������������������������������������������������� 197
Analysis������������������������������������������������������������������������������������������������������������������������������� 197
Quiz������������������������������������������������������������������������������������������������������������������������������������� 198
Output���������������������������������������������������������������������������������������������������������������������������������� 198
Analysis������������������������������������������������������������������������������������������������������������������������������� 198
is vs. as������������������������������������������������������������������������������������������������������������������������������������� 199
Demonstration 5: The Use of the “is” Keyword������������������������������������������������������������������������� 199
Output���������������������������������������������������������������������������������������������������������������������������������� 201
Analysis������������������������������������������������������������������������������������������������������������������������������� 202
Output���������������������������������������������������������������������������������������������������������������������������������� 203
Demonstration 6: The Use of the “as” Keyword������������������������������������������������������������������������ 203
Output���������������������������������������������������������������������������������������������������������������������������������� 205
Analysis������������������������������������������������������������������������������������������������������������������������������� 205
Passing Value Types by Value vs. Passing Value Types by Reference (with ref vs. out)������������ 205
Demonstration 7: Passing Value Type by Value������������������������������������������������������������������������� 206
Output���������������������������������������������������������������������������������������������������������������������������������� 206
Analysis������������������������������������������������������������������������������������������������������������������������������� 207
The ref Parameter vs. the out Parameter���������������������������������������������������������������������������������� 207
Demonstration 8����������������������������������������������������������������������������������������������������������������������� 207
Output���������������������������������������������������������������������������������������������������������������������������������� 207
Analysis������������������������������������������������������������������������������������������������������������������������������� 208

xi
Table of Contents

Demonstration 9 : The Use of the “out” Parameter������������������������������������������������������������������� 208


Output���������������������������������������������������������������������������������������������������������������������������������� 209
Analysis������������������������������������������������������������������������������������������������������������������������������� 209
Quiz������������������������������������������������������������������������������������������������������������������������������������� 210
Answer�������������������������������������������������������������������������������������������������������������������������������� 210
Analysis������������������������������������������������������������������������������������������������������������������������������� 210
Demonstration 10: Passing a Reference Type as Value������������������������������������������������������������ 211
Output���������������������������������������������������������������������������������������������������������������������������������� 211
Demonstration 11: A Case Study with Array Elements�������������������������������������������������������������� 212
Output���������������������������������������������������������������������������������������������������������������������������������� 213
Analysis������������������������������������������������������������������������������������������������������������������������������� 213
Quiz������������������������������������������������������������������������������������������������������������������������������������� 214
Output���������������������������������������������������������������������������������������������������������������������������������� 215
Analysis������������������������������������������������������������������������������������������������������������������������������� 215
Demonstration 12: A Method Returning Multiple Values����������������������������������������������������������� 215
Output���������������������������������������������������������������������������������������������������������������������������������� 216
A Brief Comparison of C# Types������������������������������������������������������������������������������������������������ 216
Value Types and Reference Types��������������������������������������������������������������������������������������������� 217
Demonstration 13: Value Types vs. Reference Types���������������������������������������������������������������� 218
Output���������������������������������������������������������������������������������������������������������������������������������� 219
Analysis������������������������������������������������������������������������������������������������������������������������������� 219
Pointer Types����������������������������������������������������������������������������������������������������������������������������� 220
Note������������������������������������������������������������������������������������������������������������������������������������� 220
Demonstration 14: Pointer Types���������������������������������������������������������������������������������������������� 221
Output���������������������������������������������������������������������������������������������������������������������������������� 222
Analysis������������������������������������������������������������������������������������������������������������������������������� 222
const vs. readonly��������������������������������������������������������������������������������������������������������������������� 223
Demonstration 15: The Use of the “const” Keyword����������������������������������������������������������������� 224
Output���������������������������������������������������������������������������������������������������������������������������������� 224
Quiz������������������������������������������������������������������������������������������������������������������������������������� 225
Answer�������������������������������������������������������������������������������������������������������������������������������� 225

xii
Table of Contents

Quiz������������������������������������������������������������������������������������������������������������������������������������� 225
Answer�������������������������������������������������������������������������������������������������������������������������������� 225
Quiz������������������������������������������������������������������������������������������������������������������������������������� 226
Answer�������������������������������������������������������������������������������������������������������������������������������� 226
Quiz������������������������������������������������������������������������������������������������������������������������������������� 226
Answer�������������������������������������������������������������������������������������������������������������������������������� 227
Quiz������������������������������������������������������������������������������������������������������������������������������������� 227
Answer�������������������������������������������������������������������������������������������������������������������������������� 227
Summary���������������������������������������������������������������������������������������������������������������������������������� 229

Chapter 9: A Quick Recap of OOP Principles in C#����������������������������������������������� 231


Quiz������������������������������������������������������������������������������������������������������������������������������������������� 231
Answers������������������������������������������������������������������������������������������������������������������������������������ 231
Note������������������������������������������������������������������������������������������������������������������������������������������ 234
Demonstration 1: Composition to Handle the Preceding Problem�������������������������������������������� 236
Output���������������������������������������������������������������������������������������������������������������������������������� 238
Analysis������������������������������������������������������������������������������������������������������������������������������� 238
Demonstration 2: An Aggregation Example������������������������������������������������������������������������������� 238
Output���������������������������������������������������������������������������������������������������������������������������������� 240
Analysis������������������������������������������������������������������������������������������������������������������������������� 241
Note������������������������������������������������������������������������������������������������������������������������������������� 241
Summary���������������������������������������������������������������������������������������������������������������������������������� 242

Part II: Get Familiar with Some Advanced Concepts������������������������� 243


Chapter 10: Delegates and Events������������������������������������������������������������������������ 245
Introduction to Delegates���������������������������������������������������������������������������������������������������������� 245
A Formal Definition�������������������������������������������������������������������������������������������������������������� 246
Demonstration 1����������������������������������������������������������������������������������������������������������������������� 246
Output���������������������������������������������������������������������������������������������������������������������������������� 247
Make Your Code Size Short������������������������������������������������������������������������������������������������� 247

xiii
Table of Contents

Demonstration 2����������������������������������������������������������������������������������������������������������������������� 248


Output���������������������������������������������������������������������������������������������������������������������������������� 249
Analysis������������������������������������������������������������������������������������������������������������������������������� 250
Quiz������������������������������������������������������������������������������������������������������������������������������������� 250
Answer�������������������������������������������������������������������������������������������������������������������������������� 251
Multicast Delegates/Chaining Delegates���������������������������������������������������������������������������������� 251
Demonstration 3����������������������������������������������������������������������������������������������������������������������� 251
Output���������������������������������������������������������������������������������������������������������������������������������� 252
Quiz������������������������������������������������������������������������������������������������������������������������������������� 253
Output���������������������������������������������������������������������������������������������������������������������������������� 254
Analysis������������������������������������������������������������������������������������������������������������������������������� 254
Covariance and Contravariance in Delegates��������������������������������������������������������������������������� 255
Covariance in Delegates/Method Group Variance���������������������������������������������������������������� 256
Demonstration 4����������������������������������������������������������������������������������������������������������������������� 256
Output���������������������������������������������������������������������������������������������������������������������������������� 257
Analysis������������������������������������������������������������������������������������������������������������������������������� 257
Contravariance in Delegates������������������������������������������������������������������������������������������������ 257
Demonstration 5����������������������������������������������������������������������������������������������������������������������� 258
Output���������������������������������������������������������������������������������������������������������������������������������� 259
Analysis������������������������������������������������������������������������������������������������������������������������������� 259
Events��������������������������������������������������������������������������������������������������������������������������������������� 260
Steps to Implement a Simple Event in C#��������������������������������������������������������������������������� 261
Demonstration 6����������������������������������������������������������������������������������������������������������������������� 262
Output���������������������������������������������������������������������������������������������������������������������������������� 263
Passing Data with Event Arguments����������������������������������������������������������������������������������������� 264
Demonstration 7����������������������������������������������������������������������������������������������������������������������� 265
Output���������������������������������������������������������������������������������������������������������������������������������� 267
Analysis������������������������������������������������������������������������������������������������������������������������������� 267
Event Accessors������������������������������������������������������������������������������������������������������������������������ 267

xiv
Table of Contents

Demonstration 8����������������������������������������������������������������������������������������������������������������������� 270


Output���������������������������������������������������������������������������������������������������������������������������������� 273
Summary���������������������������������������������������������������������������������������������������������������������������������� 274

Chapter 11: Flexibilities with Anonymous Functions������������������������������������������� 275


Anonymous Methods and Lamda Expressions�������������������������������������������������������������������������� 275
Demonstration 1����������������������������������������������������������������������������������������������������������������������� 276
Output���������������������������������������������������������������������������������������������������������������������������������� 277
Analysis������������������������������������������������������������������������������������������������������������������������������� 277
Func, Action, and Predicate Delegates�������������������������������������������������������������������������������������� 279
Func Delegates�������������������������������������������������������������������������������������������������������������������� 279
Action Delegates����������������������������������������������������������������������������������������������������������������� 281
Predicate Delegates������������������������������������������������������������������������������������������������������������ 281
Demonstration 2����������������������������������������������������������������������������������������������������������������������� 282
Output���������������������������������������������������������������������������������������������������������������������������������� 283
Summary���������������������������������������������������������������������������������������������������������������������������������� 284

Chapter 12: Generics�������������������������������������������������������������������������������������������� 285


Comparison between Generic and Non-Generic Programs������������������������������������������������������� 285
Demonstration 1: A Non-Generic Program�������������������������������������������������������������������������������� 285
Output���������������������������������������������������������������������������������������������������������������������������������� 286
Demonstration 2: A Generic Program���������������������������������������������������������������������������������������� 287
Output���������������������������������������������������������������������������������������������������������������������������������� 288
Analysis������������������������������������������������������������������������������������������������������������������������������� 288
Further Analysis������������������������������������������������������������������������������������������������������������������� 289
Note������������������������������������������������������������������������������������������������������������������������������������� 289
Demonstration 3����������������������������������������������������������������������������������������������������������������������� 290
Output���������������������������������������������������������������������������������������������������������������������������������� 290
Analysis ������������������������������������������������������������������������������������������������������������������������������ 291
Demonstration 4����������������������������������������������������������������������������������������������������������������������� 291
Output���������������������������������������������������������������������������������������������������������������������������������� 292
Analysis������������������������������������������������������������������������������������������������������������������������������� 292

xv
Table of Contents

Demonstration 5: Exercise on Self-Referenced Generic Types������������������������������������������������� 293


Output���������������������������������������������������������������������������������������������������������������������������������� 295
Analysis������������������������������������������������������������������������������������������������������������������������������� 295
A Special Keyword Default�������������������������������������������������������������������������������������������������������� 295
Demonstration 6����������������������������������������������������������������������������������������������������������������������� 295
Output���������������������������������������������������������������������������������������������������������������������������������� 296
Analysis������������������������������������������������������������������������������������������������������������������������������� 296
Demonstration 7: Assignment��������������������������������������������������������������������������������������������������� 296
Output���������������������������������������������������������������������������������������������������������������������������������� 299
Generic Constraints������������������������������������������������������������������������������������������������������������������� 299
Demonstration 8����������������������������������������������������������������������������������������������������������������������� 299
Output���������������������������������������������������������������������������������������������������������������������������������� 301
Note������������������������������������������������������������������������������������������������������������������������������������� 302
Quiz������������������������������������������������������������������������������������������������������������������������������������� 303
Answer�������������������������������������������������������������������������������������������������������������������������������� 303
Covariance and Contravariance������������������������������������������������������������������������������������������������ 303
Demonstration 9: Covariance with Generic Interfaces�������������������������������������������������������������� 307
Output���������������������������������������������������������������������������������������������������������������������������������� 309
Analysis������������������������������������������������������������������������������������������������������������������������������� 309
Demonstration 10: Contravariance with Generic Delegates������������������������������������������������������ 309
Output���������������������������������������������������������������������������������������������������������������������������������� 311
Analysis������������������������������������������������������������������������������������������������������������������������������� 311
Summary���������������������������������������������������������������������������������������������������������������������������������� 312

Chapter 13: Exception Handling��������������������������������������������������������������������������� 313


Discussions on Exception Handling������������������������������������������������������������������������������������������ 313
Definition����������������������������������������������������������������������������������������������������������������������������������� 313
Demonstration 1����������������������������������������������������������������������������������������������������������������������� 314
Output���������������������������������������������������������������������������������������������������������������������������������� 315
Demonstration 2����������������������������������������������������������������������������������������������������������������������� 316
Output���������������������������������������������������������������������������������������������������������������������������������� 317
Analysis������������������������������������������������������������������������������������������������������������������������������� 317
xvi
Table of Contents

Demonstration 3����������������������������������������������������������������������������������������������������������������������� 321


Output���������������������������������������������������������������������������������������������������������������������������������� 324
Analysis������������������������������������������������������������������������������������������������������������������������������� 325
Quiz������������������������������������������������������������������������������������������������������������������������������������� 325
Demonstration 4����������������������������������������������������������������������������������������������������������������������� 325
Output���������������������������������������������������������������������������������������������������������������������������������� 326
Analysis������������������������������������������������������������������������������������������������������������������������������� 326
Other Variations of the catch Clause����������������������������������������������������������������������������������� 327
Quiz������������������������������������������������������������������������������������������������������������������������������������� 327
Answer�������������������������������������������������������������������������������������������������������������������������������� 328
Quiz������������������������������������������������������������������������������������������������������������������������������������� 328
Answer�������������������������������������������������������������������������������������������������������������������������������� 328
Explanation�������������������������������������������������������������������������������������������������������������������������� 328
Demonstration 5����������������������������������������������������������������������������������������������������������������������� 330
Output���������������������������������������������������������������������������������������������������������������������������������� 331
Demonstration 6����������������������������������������������������������������������������������������������������������������������� 332
Output���������������������������������������������������������������������������������������������������������������������������������� 334
Analysis������������������������������������������������������������������������������������������������������������������������������� 334
Creating a Custom Exception���������������������������������������������������������������������������������������������������� 335
Demonstration 7����������������������������������������������������������������������������������������������������������������������� 336
Output���������������������������������������������������������������������������������������������������������������������������������� 338
Analysis������������������������������������������������������������������������������������������������������������������������������� 338
Summary���������������������������������������������������������������������������������������������������������������������������������� 339

Chapter 14: Memory Cleanup������������������������������������������������������������������������������� 341


How the Garbage Collector Works�������������������������������������������������������������������������������������������� 342
Three Phases of Garbage Collection������������������������������������������������������������������������������������ 342
Three Cases to invoke the Garbage Collector���������������������������������������������������������������������� 343
Demonstration 1����������������������������������������������������������������������������������������������������������������������� 343
Output���������������������������������������������������������������������������������������������������������������������������������� 347
Analysis������������������������������������������������������������������������������������������������������������������������������� 347

xvii
Table of Contents

Memory Leak Analysis�������������������������������������������������������������������������������������������������������������� 351


Demonstration 2����������������������������������������������������������������������������������������������������������������������� 352
Snapshots from Diagnostic Tool������������������������������������������������������������������������������������������ 354
Demonstration 3����������������������������������������������������������������������������������������������������������������������� 355
Snapshots from CLR Profiler����������������������������������������������������������������������������������������������� 357
Analysis������������������������������������������������������������������������������������������������������������������������������� 357
Let us modify the program�������������������������������������������������������������������������������������������������� 359
Analysis������������������������������������������������������������������������������������������������������������������������������� 361
Demonstration 4����������������������������������������������������������������������������������������������������������������������� 363
Output���������������������������������������������������������������������������������������������������������������������������������� 364
Demonstration 5����������������������������������������������������������������������������������������������������������������������� 365
Output���������������������������������������������������������������������������������������������������������������������������������� 366
Demonstration 6����������������������������������������������������������������������������������������������������������������������� 366
Output���������������������������������������������������������������������������������������������������������������������������������� 367
Quiz������������������������������������������������������������������������������������������������������������������������������������� 368
Output���������������������������������������������������������������������������������������������������������������������������������� 370
Quiz������������������������������������������������������������������������������������������������������������������������������������� 370
Answer�������������������������������������������������������������������������������������������������������������������������������� 370
Analysis������������������������������������������������������������������������������������������������������������������������������� 370
Summary���������������������������������������������������������������������������������������������������������������������������������� 371

Part III: Become a Hero in the Real World����������������������������������������� 373


Chapter 15: An Introduction to Design Patterns��������������������������������������������������� 375
Introduction������������������������������������������������������������������������������������������������������������������������������� 375
Key Points��������������������������������������������������������������������������������������������������������������������������������� 376
Singleton Pattern���������������������������������������������������������������������������������������������������������������������� 379
GoF Definition���������������������������������������������������������������������������������������������������������������������� 379
Concept������������������������������������������������������������������������������������������������������������������������������� 379
A Real-life Example������������������������������������������������������������������������������������������������������������� 379
A Computer-World Example������������������������������������������������������������������������������������������������� 379
Illustration��������������������������������������������������������������������������������������������������������������������������� 379

xviii
Table of Contents

Class Diagram��������������������������������������������������������������������������������������������������������������������� 380


Solution Explorer View��������������������������������������������������������������������������������������������������������� 380
Discussion��������������������������������������������������������������������������������������������������������������������������� 381
Implementation������������������������������������������������������������������������������������������������������������������� 381
Challenges��������������������������������������������������������������������������������������������������������������������������� 383
Q&A Session������������������������������������������������������������������������������������������������������������������������ 384
Adapter Pattern������������������������������������������������������������������������������������������������������������������������� 387
GoF Definition���������������������������������������������������������������������������������������������������������������������� 387
Concept������������������������������������������������������������������������������������������������������������������������������� 387
A Real-Life Example������������������������������������������������������������������������������������������������������������ 387
A Computer-World Example������������������������������������������������������������������������������������������������� 388
Illustration��������������������������������������������������������������������������������������������������������������������������� 388
Class Diagram��������������������������������������������������������������������������������������������������������������������� 389
Directed Graph Document��������������������������������������������������������������������������������������������������� 389
Solution Explorer View��������������������������������������������������������������������������������������������������������� 390
Implementation������������������������������������������������������������������������������������������������������������������� 390
Solution Explorer View��������������������������������������������������������������������������������������������������������� 394
Implementation������������������������������������������������������������������������������������������������������������������� 394
Q&A Session������������������������������������������������������������������������������������������������������������������������ 399
Visitor Pattern��������������������������������������������������������������������������������������������������������������������������� 400
GoF Definition���������������������������������������������������������������������������������������������������������������������� 400
Concept������������������������������������������������������������������������������������������������������������������������������� 400
A Real-Life Example������������������������������������������������������������������������������������������������������������ 400
A Computer-World Example������������������������������������������������������������������������������������������������� 400
Illustration��������������������������������������������������������������������������������������������������������������������������� 401
Class Diagram��������������������������������������������������������������������������������������������������������������������� 402
Solution Explorer View��������������������������������������������������������������������������������������������������������� 403
Implementation������������������������������������������������������������������������������������������������������������������� 403
Q&A Session������������������������������������������������������������������������������������������������������������������������ 405
Summary���������������������������������������������������������������������������������������������������������������������������������� 406

xix
Table of Contents

Chapter 16: Winning Notes and the Road Ahead�������������������������������������������������� 407

Appendix A: Collect the Raw Materials���������������������������������������������������������������� 409


F undamentals��������������������������������������������������������������������������������������������������������������������������� 409
Theory��������������������������������������������������������������������������������������������������������������������������������� 409
Selection Statements���������������������������������������������������������������������������������������������������������������� 416
Types of Selection��������������������������������������������������������������������������������������������������������������� 416
An Example of if-else���������������������������������������������������������������������������������������������������������� 416
An Example of switch Statements��������������������������������������������������������������������������������������� 418
Iteration Statements����������������������������������������������������������������������������������������������������������������� 423
Demonstration��������������������������������������������������������������������������������������������������������������������� 424
Demonstration��������������������������������������������������������������������������������������������������������������������� 425
Jump Statements���������������������������������������������������������������������������������������������������������������������� 431
Demonstration��������������������������������������������������������������������������������������������������������������������� 431
Miscellaneous��������������������������������������������������������������������������������������������������������������������������� 435
Strings��������������������������������������������������������������������������������������������������������������������������������������� 437
Questions/Answers with code segments���������������������������������������������������������������������������� 437
Arrays���������������������������������������������������������������������������������������������������������������������������������������� 449
Single Dimensional Arrays��������������������������������������������������������������������������������������������������� 449
Demonstration��������������������������������������������������������������������������������������������������������������������� 449
Demonstration��������������������������������������������������������������������������������������������������������������������� 451
Demonstration��������������������������������������������������������������������������������������������������������������������� 453
Enumerations���������������������������������������������������������������������������������������������������������������������������� 460
Demonstration��������������������������������������������������������������������������������������������������������������������� 460
Demonstration��������������������������������������������������������������������������������������������������������������������� 462
Demonstration��������������������������������������������������������������������������������������������������������������������� 466
Structures��������������������������������������������������������������������������������������������������������������������������������� 471
Demonstration��������������������������������������������������������������������������������������������������������������������� 471
Demonstration��������������������������������������������������������������������������������������������������������������������� 472

xx
Table of Contents

Appendix B: FAQ��������������������������������������������������������������������������������������������������� 481

Appendix C: References���������������������������������������������������������������������������������������� 487

Index��������������������������������������������������������������������������������������������������������������������� 489

xxi
Foreword by Ambrose Rajendram
I have spent most of my career working in R&D and related
activities. During this time, I have come in contact with
many engineers across many disciplines and of differing
caliber and attitudes. As a rule, engineers spend most of
their life acquiring knowledge, which is even truer in today’s
fast-changing technological landscape. Vaskaran is one such
engineer who is on an eternal quest to try new boundaries.
What makes Vaskaran different, though, is that he has an
unbridled passion to share his knowledge and make it
available to the world. It is an honor and a privilege to write
this foreword.
In the connected world we live in, there is an abundance of knowledge. It sometimes
seems that textbooks are superfluous, as this information is available free on the Internet.
However, what this book does is take the reader through a set of logical steps from the basics
to advanced concepts. This flow is very important to understand the fundamental building
blocks. Once the reader has a grasp of this, it will be relatively easy to advance further.
This book concentrates on what is required to understand the subject and leaves
out unnecessary things. Each chapter introduces a new concept and the author has
anticipated questions that the reader may have and preempts this through simple Q&A
analogies as would happen in a classroom. This provides insights that lead to a deeper
understanding of the concepts.
Object-oriented programming is the most essential concept in software engineering
today and understanding this is crucial to good programming. The author has done
a phenomenal job of presenting this in a simple way that is easy to understand. Use
this book as a companion guide on your journey through the complex world of object-­
oriented programming. I hope that this book will be as useful to you as it was to me.
—Ambrose Rajendram

xxiii
Foreword by Ambrose Rajendram

About Ambrose Rajendram


Ambrose is a Master Technologist at Hewlett-Packard’s R&D Centre in India. He is an
electronics engineer by education but his passion for technology has led him to different
areas, from mechanical engineering to robotics and machine learning. He is presently
working on applying machine learning to robotics to solve everyday problems.

xxiv
Foreword by Siddhartha Ghosh
There is no dearth of books on any programming language,
particularly on a programming language as popular as C#.
There are definitive textbooks by authors who are active
contributors to the development of the language. Most of
the time, however, these books prove too challenging for a
normal reader to understand. On the other hand, there are
books that are very easy to read, but they compromise the
accuracy of the concepts covered. Vaskaran, having been a
teacher himself in the initial phase of his career, understands
the challenges faced by the students in developing a solid foundation in programming.
His unique student-teacher dialog approach provides the reader a strong foundation on
fundamental concepts without making matters overly complex. In addition to the strong
fundamentals, Vaskaran has also included some crucial pieces of information from his
professional life. The chapter on memory cleanup is an example of this. I am very sure
that this book is going to provide the readers a good understanding of the topics in a
clear and interesting way.
—Siddhartha Ghosh

About Siddhartha Ghosh


Siddhartha is postgraduate in statistics and information technology. He is working as
a Solutions Architect in enterprise print domain at Hewlett-Packard’s R&D division in
Bangalore. He has more than 18 years of experience in the IT industry in various roles and
capacities. He obtained his MBA in quality management and he always tries to discover
ways in which he can apply his acquired skills set at work.

xxv
Another random document with
no related content on Scribd:
Inhoudsopgave

VOORWOORD. VII
GEBEZIGDE LITTERATUUR. XI
INHOUD. XIII
LIJST VAN ILLUSTRATIES. XV
VERBETERINGEN. XVI
I. INDIANEN-BEVOLKING VAN WEST-INDIË. 1
Inleidende beschouwingen. 1
Inhoud der verhalen 7
Lijst der in dezen bundel opgenomen mondelinge
overleveringen der Indianen. 14
Indianen-Vertellingen. 66
1. De sage van Haboeri (W.) 66
2. De oorsprong der eerste menschen (C.) 73
3. De oorsprong van het menschdom (W.) 75
4. De oorsprong der Caraïben. (C.) 76
5. Hoe de Caraïben gekweekte planten leerden
kennen. (C.) 77
6. De dochter van den geestenbezweerder. 79
7. Hoe lichaamspijnen, dood en ellende in de wereld
kwamen. (C.) 81
8. Het hoofd van den Boschgeest en de nachtzwaluw.
(A.) 83
9. De vrouw, die een Boschgeest nabootste. (A.) 84
10. De Geest van een schimmelplant* redt een 86
Indiaansch meisje. (C.)
11. Een jagoear, die in een vrouw veranderde. (A.) 89
12. De man met een Baboen-vrouw. (A.) 91
13. Schildpad, die Boschrat er in liet loopen. (C.) 94
14. De bedrieger bedrogen. (C.) 95
15. Tijger en Miereneter. (C.) 96
16. Hariwali en de Wonderboom. (A.) 98
17. De legende van den Ouden man’s val. 103
18. Amanna en haar praatzieke man. (C.) 105
19. De zon en zijn beide tweelingzoons. (C.) 107
20. De Legende van den Vleermuis-berg. (M.) 111
21. De Uil en zijn schoonbroeders vleermuis. (W.) 112
22. De Lichtkever en de verdwaalde Jager. (C.) 114
23. De bina, de weder in het leven geroepen vader en de
slechte vrouw. (W.) 116
24. Hoe een jong Warrau-Indiaantje uit de handen der
Caraïben ontkwam. (W.) 119
25. Sluit de oogen en doe een wensch. (C.) 121
26. De gelukspot. (W.) 122
27. De honigbij en de zoete drank. (W.) 124
28. De piaiman en de stinkvogels*. (A.) 125
29. Hoe het ongeluk over de menschen kwam. De
geschiedenis van Maconaura en Anoeannaïtoe. (A.) 131
30. De kolibri, die tabak brengt aan den eersten piaiman.
(W.) 140
31. Het ontstaan der vrouwennaties. 145
32. Het gebroken ei. 146
33. De geest van den pasgeborene. 146
34. De huid van den Reuzenslang of Hoe de vogels hun 147
tegenwoordig gevederte kregen.
35. Een waarschuwing voor de vrouwen. (A.) 148
36. Hoe een man van zijn luiheid genezen werd. (W.) 155
37. Zwarte Tijger, Wau-oeta en de gebroken boog. (W.) 157
38. De Legende van Letterhoutstomp. 162
39. De Legende van Arimoribo en Jorobodie. (C.) 165
40. Uitdrijven van een priester uit den Indiaanschen
hemel. 170
41. Uitdrijving der Indianen uit den Hemel der Paters. 174
42. Bezoek van Caraïben aan Macoesiland. (C.) 178
43. Legende van Paramaribo. 179
44. De Legende van Post Sommelsdijk. 180
45. Einde van den Indiaanschen broederoorlog. (A.) 182
46. De groote bloedzuigende vleermuis. (A.) 183
47. Legende van Mapajawari of de uitroeiing der
menscheneters. (C.) 184
48. Migratie-legende van den Kasi’hta-stam der Creek-
Indianen, 189
II. West-Indische neger-folklore. 197
Inleidende beschouwingen. 197
De Surinaamsche Anansi-tori’s en hare oorsprong. 203
LIJST DER NEGERVERTELLINGEN. 235
Inhoud der Surinaamsche Negervertellingen. 237
De anansi-tori en het bijgeloof. 246
VERTELLINGEN DER SURINAAMSCHE
STADSNEGERS. 258
1. Anansi, die een half dorp verovert. 258
2. Spin en de Prinses. 266
3. Het huwelijk van Heer Spin. 271
4. Anansi, Tijger en de doode Koe. 273
5. Anansi en zijn kinderen. 276
6. Hoe Spin zijn schuldeischers betaalt. 277
7. Een feest bij de Waternimf. 281
8. Anansi en Kat. 282
9. Spin en Krekel. 285
10. Heer Spin als Geestelijke. 286
11. Heer Spin als roeier. 287
12. Spin neemt Tijger gevangen. 289
13. Heer Spin en Hond. 291
14. Tijger’s verjaardag. 293
15. Spin voert den Dood in. 295
16. Spin wedt, Tijger te berijden. 297
17. Verhaal uit het leven van vriend Spin. 299
18. Anansi als Amerikaan verkleed. 303
19. Heer Spin en de Waternimf. 305
20. Anansi, Hert en Kikvorsch. 306
21. Heer Spin als landbouwer. 308
22. Anansi en de Bliksem. 310
23. Ieder volwassen man moet een rood zitvlak hebben. 315
24. Hoe Anansi aan schapenvleesch wist te komen. 318
25. De geschiedenis van Fini Foetoe, Bigi bere en Bigi
hede. 321
26. Legende van Leisah I. 323
27. Legende van Leisah. II. 325
28. Verhaal van het land van „Moeder Soemba”. 327
29. Boen no habi tangi. 330
30. Geschiedenis van Kopro Kanon*. 332
31. De Meermin of Watramama. 335
32. De Boa in de gedaante van een schoonen jongeling. 337
33. Het huwelijk van Aap. 339
DE ANANSI-TORI DER SURINAAMSCHE
BOSCHNEGERS. 342
Hoe Heer Spin door zijn bekwaamheid als
geneesheer de mooie dochter van den Landvoogd
wist te krijgen. 345
NEGER-VERTELLINGEN UIT HET WEST-INDISCHE
EILANDENGEBIED. 350
Curaçaosche Negervertellingen. Cuenta di Nansi. 350
Nansi en Temekóe-Temebè. 354
Creoolsche folk-lore van St.-Eustatius. 360
Braha- Nanci en Braha-Toekema. 362
Neger-vertellingen van Jamaica. Nancy-Stories. 367
1. Annancy in Krabbenland. 371
2. Reiger. 373
3. Annancy, Poes en Rat. 377
BIJVOEGSELS. 379
I. NEGER-SPREEKWOORDEN. 379
Suriname. 379
West-Afrika. 381
II. AVOND OP HET WATER in Sierra Leone 384
Spin, Olifant en Hippopotamus. 389
III. DIEREN-FABEL, 393
Wie zijn Krokodil’s verwanten? 393
VERKLAREND REGISTER. 396
A. 396
B. 397
C. 399
D. 400
E. 400
F. 400
G. 401
H. 401
I. 402
J. 402
K. 403
L. 406
M. 407
N. 408
O. 408
P. 409
R. 411
S. 411
T. 413
V. 414
W. 415
Y. 416
Z. 416
Colofon
Beschikbaarheid

Dit eBoek is voor kosteloos gebruik door iedereen overal, met vrijwel
geen beperkingen van welke soort dan ook. U mag het kopiëren,
weggeven of hergebruiken onder de voorwaarden van de Project
Gutenberg Licentie in dit eBoek of on-line op www.gutenberg.org ↗️.

Dit eBoek is geproduceerd door het on-line gedistribueerd


correctieteam op www.pgdp.net ↗️.

Van dit boek zijn on-line scans beschikbaar: exemplaar 1, 2, 3.

Metadata

Titel: Mythen en
sagen uit
West-Indië
Auteur: Herman Info https://viaf.org/viaf/45474713/
van
Cappelle
Jr. (1857–
1932)
Illustrator: Willem Info
Antonius https://viaf.org/viaf/3295167202597667930008/
Josef
Backer
(1901–
1971)
Aanmaakdatum 2023-11-14
bestand: 20:38:53
UTC
Taal: Nederlands
(Spelling
De Vries-
Te Winkel)
Oorspronkelijke 1926
uitgiftedatum:

Codering

Dit boek is weergegeven in oorspronkelijke schrijfwijze. Afgebroken


woorden aan het einde van de regel zijn stilzwijgend hersteld.
Kennelijke zetfouten in het origineel zijn verbeterd. Deze verbeteringen
zijn aangegeven in de colofon aan het einde van dit boek.

De muziek in dit boek is getranscribeerd en zowel als MP3 en


MusicXML bestanden beschikbaar gemaakt. Links naar deze
bestanden staan onder de muzieknotatie.

Documentgeschiedenis

2023-10-19 Begonnen.

Externe Referenties

Project Gutenberg plaatst geen actieve externe links in haar eboeken.


De volgende URL's worden puur ter informatie getoond. U kunt ze
desgewenst naar de adresbalk van uw browser kopiëren.

Bladzijde URL
n.v.t. https://archive.org/details/BNA-DIG-CARI-918-CAPP
n.v.t. https://hdl.handle.net/1887.1/item:948616
n.v.t. https://www.delpher.nl/nl/boeken/view?
identifier=MMKB02:000123099:00004

Verbeteringen

De volgende verbeteringen zijn aangebracht in de tekst:

Bladzijde Bron Verbetering Bewerkingsafstand


n.v.t. GEILLUSTREERD GEÏLLUSTREERD 1/0
VII symphatieke sympathieke 2
XII, 165, [Niet in bron] ) 1
243, 408
XII, 400,
407 . [Verwijderd] 1
Passim. [Niet in bron] . 1
XII Volkenkunden Volkenkunde 1
XII Smithonian Smithsonian 1
XII reports report 1
XIII, 350,
350 St. Eustachius St.-Eustatius 3
XVI wreedzaam wreedzame 2
XVI vreedzaam vreedzame 2
XVI, 26,
46, 58,
158, 203,
253, 276,
287, 328,
356, 403,
405, 406,
410, 410,
412 , . 1
2 wreedzame vreedzame 1
4, 76, 76 wêer weêr 2/0
5 hebben heb 3
7 nêergelegd neêrgelegd 2/0
7 geïdialiseerd geïdealiseerd 1
8 Mythen-cathegorie Mythen-categorie 1
9, 207 beinvloed beïnvloed 1/0
11 met [Verwijderd] 4
12 beinvloeden beïnvloeden 1/0
13 Travells Travels 1
14, 92,
119, 222,
276, 287,
329, 355 — 1
17 af komstig afkomstig 1
17 voor voort 1
20, 165,
214, 214,
243, 334 . , 1
24 lichamspijnen lichaamspijnen 1
25 Anoeannaitoe Anoeannaïtoe 1/0
28 verweringskorst verweeringskorst 1
28 Indiaaan Indiaan 1
29, 409 over dag overdag 1
29, 164,
165 Caraiben Caraïben 1/0
31 demaan de maan 1
Passim. [Niet in bron] „ 1
Passim. Penard’s Penards 1
33 Caraibische Caraïbische 1/0
33 de de de 3
33 heuvel hemel 2
33 19 20 2
34 van daan vandaan 1
39 hebben heeft 4
40, 106,
106, 122 broer broêr 1/0
Passim. [Niet in bron] ” 1
41 jaguar jagoear 2
44 ,* *, 2
45 kalabassen kalebassen 1
47 Indíaansche Indiaansche 1/0
54 Missisippi-stroom Mississippi-stroom 1
55, 189 Ogleterpe Oglethorpe 2
55 Tchikili Tchikilli 1
56 mais maïs 1/0
60 Tot In 3
61 bij hij 1
62 Natuur Natur 1
63, 72 papagaai papegaai 1
66 Pallissade-palm Palissadepalm 2
69 antwoorde antwoordde 1
72 Onmiddelijk Onmiddellijk 1
74 gopend geopend 1
76 weér weêr 1/0
78, 125,
183, 184,
229, 264,
283, 294,
313, 321,
332, 336,
354 .* *. 2
78 lotgenoten lotgenooten 1
78 Allepäntepo Allepántepo 1/0
81 Jorokas Joroka’s 1
81, 117,
128, 233,
410 , [Verwijderd] 1
84 ”. .” 2
84, 148,
314, 314 mee meê 1/0
86 broers broêrs 1/0
96 lachtte lachte 1
97 Tamanoe Tamanoea 1
112 schoonbroeder schoonbroeders 1
112 broêr broêrs 1
114 schoonbroers schoonbroêrs 1/0
117 vermoordde vermoorde 1
121 hadden had 3
122 verweringsprodukten verweeringsprodukten 1
123 çassave-gerecht cassavegerecht 2/1
124, 364,
391 „ [Verwijderd] 1
127 van een van een van een 8
128 weer weêr 1/0
131 Agouti Agoeti 1
133, 141 schreidde schreide 1
133 Anoennaïtoe Anoeannaïtoe 1
134 uw Uw 1
135 Kakoutji Kaikoutji 1
137 wraken wrake 1
139 Anoeannitoe Anoeannaïtoe 2/1
142, 142 hem hen 1
142 zij hij 1
142 zouden zou 3
150 probeerden probeerde 1
151 weefpatroon vlechtpatroon 5
157 Tobe-heroanna Tobe-horoanna 1
158, 255,
264, 269,
269, 276,
376 [Niet in bron] , 1
158 tijger Tijger 1
159 ”* *” 2
162 niet [Verwijderd] 5
163, 164 Caraibisch Caraïbisch 1/0
164 Marorwijne Marowijne 1
164 Corantyn Corantijn 2
164 Marorvijne Marowijne 2
166 slotten slotte 1
170, 340 ” [Verwijderd] 1
183 Nu nu 1
184 uitroeiïng uitroeiing 1/0
185 zijn’s zijn 2
188 vluchtten vluchten 1
189 kanibalen kannibalen 1
189 achtiende achttiende 1
189 Kanibalenstam Kannibalenstam 1
189 Kanibalen Kannibalen 1
189 Giorgia Georgia 1
196 Ogletherpe Oglethorpe 1
198 dède hóso déde-hóso 2/1
201 negervertelingen negervertellingen 1
202 - [Verwijderd] 1
207 Neger-engelsche Neger-Engelsche 1
210 [Niet in bron] in 3
212 lostte loste 1
212, 239 Jamaïca Jamaica 1/0
220 Boesi-gramman Boesi-granman 1
229 Python’s Pythons 1
229 synonym synoniem 2
230 Aequtoriaal Aequatoriaal 1
231 Rabit Rabbit 1
233 Sierre Sierra 1
236 Temekoe-Temebe Temekóe-Temebè 2/0
239 Awarì-bang Awari-bángi 3/1
240 Negerengelsch Neger-Engelsch 2
243 Je Je 0
244 von van 1
246 lachtten lachten 1
246 anansi tori’s anansi-tori’s 1
247 kreool Creool 1
247 déde hóso déde-hóso 1
251 déde-hoso déde-hóso 1/0
251 arratta aratta 1
252 wachvrouw waschvrouw 1
252 Idiaansche Indiaansche 1
253, 296,
363 neer neêr 1/0
254 abormalen abnormalen 1
256, 256,
256 u U 1
267, 268 Jou Jouw 1
268, 277, jou jouw 1
284
269 „ ” 2
269 ” ,„ 2
272 anansi’s Anansi’s 1
276 Ma’ ’Ma 2
276 julie jullie 1
278 [Niet in bron] Vos 4
282, 295 anansi Anansi 1
282 anansì Anansi 2/1
282 Pína Pina 1/0
296, 304,
310, 311,
312, 312,
314, 314 Anansí Anansi 1/0
299, 307 anansí Anansi 2/1
303 broeders Broeders 1
303 zusters Zusters 1
303 Kosi Kósi 1/0
303 [Niet in bron] ,” 2
307, 338 wordt word 1
310, 310 10.000 10,000 1
311 . : 1
311 ! ? 1
313 buikpuin buikpijn 2
314 . ? 1
319 korsten kortsten 1
320 huigelachtige huichelachtige 2
322 broertjes broêrtjes 1/0
324 moeder Moeder 1
324 Vader’s Vaders 1
324 vaders Vaders 1
326 schuim Schuim 1
329, 329 Ma ’Ma 1
331 uit uit uit 4
332 ! : 1
333, 334,
334 Minimini Mininimi 2
334 patient patiënt 1/0
334 Kapro Kopro 1
338 wij Wij 1
338 er Er 1
340 gebruike gebruikelijke 5
344 Hoevell Hoëvell 1/0
345 spin-vertelling spinvertelling 1
348 verergde verergerde 2
348 hoelanger hoe langer 1
349 Spin’s Spins 1
350 voornaamsche voornaamste 2
350 dagens dagen 1
354 papiemento papiamento 1
357 guyave guave 1
365 St. Eustatius St.-Eustatius 1
370 kamplaats kampplaats 1
370 banencultuur bananencultuur 2
373 vrienden vriend 2
376 hollandsche Hollandsche 1
379 zachtzinige zachtzinnige 1
380 Iffi iffi 1
381 Houd Houdt 1
381 okro okra 1
381, 381 houd houdt 1
383 zend zendt 1
386 melodiën melodieën 1
390 houdt houd 1
394, 394 veèren veêren 1/0
396 Neger-engelsch Neger-Engelsch 1
396 Amalavica Amalivaca 2
399 [Niet in bron] : 1
399 Eunctus Eunectus 1
399 Piaaiman Piaiman 1
400 Mrs Mrs. 1
400 Dokoen Dokóen 1/0
400 Dokoenboom Dokóenboom 1/0
401 NE. N.E. 1
401 donkerebruinen donkerbruinen 1
402 Auruba Aruba 1
402 Dominico Dominica 1
402 Onca onca 1
403 Anacardicum Anacardium 1
405 Kopra Kanon Kópro Kanón 3/1
405 ,) ), 2
405, 416 [Niet in bron] - 1
406 kankantree kankantrie 1
407 Maconoura Maconaura 1
407 waarmêe waarmeê 2/0
408 Massoewa Masoewa 1
408 Winnamoeroe Winnamoroe 1
409 Ooloekwa-toelala Oeloekwa-toelala 1
409 [Niet in bron] ( 1
409 Okro Okra 1
409 ( [Verwijderd] 1
409 ) [Verwijderd] 1
410 Ipomaea Batatas Ipomoea batatas 2
413 [Niet in bron] L. 3
414 Verweerings-korst Verweeringskorst 1
414 Zuid-America Zuid-Amerika 1
415 Blondii blondii 1
415, 416 N.-E. N.E. 1
416 Magroveboomen Mangroveboomen 1

Afkortingen
Overzicht van gebruikte afkortingen.

Afkorting Uitgeschreven
N.B. noorderbreedte
N.B. Nota bene
N.E. Neger-Engelsch
Ned.-Indië Nederlandsch-Indië
W.-I. West-Indië
Z.O. zuidoostelijke
Z.O. zuidoost
*** END OF THE PROJECT GUTENBERG EBOOK MYTHEN EN
SAGEN UIT WEST-INDIË ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright
in these works, so the Foundation (and you!) can copy and
distribute it in the United States without permission and without
paying copyright royalties. Special rules, set forth in the General
Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree to
abide by all the terms of this agreement, you must cease using
and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.

You might also like