Murach's C# - How to work with interfaces, structures, and class libraries

Although a C# class can inherit only one class, it can also implement one or more interfaces. So in this chapter, you'll learn how to create and implement a C# interface, and you'll specifically learn how to implement the ICloneable, IEnumerable, and IEnumerator interfaces. After that, you'll learn how to create and use structures, which are similar to classes but define value types rather than reference types. And you'll learn how to make your classes easier to use by storing them in class libraries.

Chapter 15 How to work with interfaces, structures, and class libraries
How to work with interfaces 440
An introduction to interfaces 440
Some of the interfaces defined by the .NET Framework 442
How to create an interface 444
How to implement an interface 446
A Product class that implements the ICloneable interface 448
How to use an interface as a parameter 450
An example that implements the enumerator interfaces 452
The IEnumerable interface 452
The IEnumerator interface 452
The code for the ProductList class 454
The code for the ProductEnumerator class 454
Code that uses the ProductList enumerator 456
How to work with structures 458
How to create a structure 458
How to use a structure 458
How to create and use class libraries 460
How class libraries work 460
How to create a class library project 462
How to add a reference to a class library 464
How to use the classes in a class library 464




Murach's C#

Learn more about this book

Add this book to your cart



Our Ironclad Guarantee

First, try our books for 90 days. Then, if you aren't completely convinced that our books are the best ones you've ever used, you can return them for a full refund...no questions asked.