112
// Defines default functionality and definitions
abstract class Shape
{
public int x = 100, y = 100;
public abstract int GetArea();
}
class Rectangle : Shape {} // class is a Shape
// Defines an interface
or a specific functionality
interface IComparable
{
int Compare(object o);
}
class MyClass : IComparable {} // class can be compared
An abstract class,
just like a non-abstract class, can extend one base
class and implement any number of interfaces. An interface, however,
cannot inherit from a class. It can inherit from another interface, which
effectively combines the two interfaces into one.
Chapter 18 abstraCt
113
© Mikael Olsson 2020
M. Olsson,
C# 8 Quick Syntax Reference,
https://doi.org/10.1007/978-1-4842-5577-3_19
CHAPTER 19
Namespaces
Namespaces provide a way to group related top-level members into
a hierarchy. They are also used to avoid naming conflicts. A top-level
member, such as a class, that is not included
in a namespace is said to
belong to the default namespace. It can be moved to another namespace
by being enclosed in a namespace block. The naming convention for
namespaces is the same as for classes, with each word initially capitalized.
namespace MyNamespace
{
class MyClass {}
}
Do'stlaringiz bilan baham: