แก้ไข

แชร์ผ่าน


.NET class library overview

.NET APIs include classes, interfaces, delegates, and value types that expedite and optimize the development process and provide access to system functionality. To facilitate interoperability between languages, most .NET types are CLS-compliant and can therefore be used from any programming language whose compiler conforms to the common language specification (CLS).

.NET types are the foundation on which .NET applications, components, and controls are built. .NET includes types that perform the following functions:

  • Represent base data types and exceptions.
  • Encapsulate data structures.
  • Perform I/O.
  • Access information about loaded types.
  • Invoke .NET security checks.
  • Provide data access, rich client-side GUI, and server-controlled, client-side GUI.

.NET provides a rich set of interfaces, as well as abstract and concrete (non-abstract) classes. You can use the concrete classes as-is or, in many cases, derive your own classes from them. To use the functionality of an interface, you can either create a class that implements the interface or derive a class from one of the .NET classes that implements the interface.

Naming conventions

.NET types use a dot syntax naming scheme that connotes a hierarchy. This technique groups related types into namespaces so they can be searched and referenced more easily. The first part of the full name—up to the rightmost dot—is the namespace name. The last part of the name is the type name. For example, System.Collections.Generic.List<T> represents the List<T> type, which belongs to the System.Collections.Generic namespace. The types in System.Collections.Generic can be used to work with generic collections.

This naming scheme makes it easy for library developers extending .NET to create hierarchical groups of types and name them in a consistent, informative manner. It also allows types to be unambiguously identified by their full name (that is, by their namespace and type name), which prevents type name collisions. Library developers are expected to use the following convention when creating names for their namespaces:

CompanyName.TechnologyName

For example, the namespace Microsoft.Word conforms to this guideline.

The use of naming patterns to group related types into namespaces is a useful way to build and document class libraries. However, this naming scheme has no effect on visibility, member access, inheritance, security, or binding. A namespace can be partitioned across multiple assemblies and a single assembly can contain types from multiple namespaces. The assembly provides the formal structure for versioning, deployment, security, loading, and visibility in the common language runtime.

For more information on namespaces and type names, see Common Type System.

System namespace

The System namespace is the root namespace for fundamental types in .NET. This namespace includes classes that represent the base data types used by all applications, for example, Object (the root of the inheritance hierarchy), Byte, Char, Array, Int32, and String. Many of these types correspond to the primitive data types that your programming language uses. When you write code using .NET types, you can use your language's corresponding keyword when a .NET base data type is expected.

The following table lists the base types that .NET supplies, briefly describes each type, and indicates the corresponding type in Visual Basic, C#, C++, and F#.

Category Class name Description Visual Basic data type C# data type C++/CLI data type F# data type
Integer Byte An 8-bit unsigned integer. Byte byte unsigned char byte
SByte An 8-bit signed integer.

Not CLS-compliant.
SByte sbyte char or signed char sbyte
Int16 A 16-bit signed integer. Short short short int16
Int32 A 32-bit signed integer. Integer int int or long int
Int64 A 64-bit signed integer. Long long __int64 int64
UInt16 A 16-bit unsigned integer.

Not CLS-compliant.
UShort ushort unsigned short uint16
UInt32 A 32-bit unsigned integer.

Not CLS-compliant.
UInteger uint unsigned int or unsigned long uint32
UInt64 A 64-bit unsigned integer.

Not CLS-compliant.
ULong ulong unsigned __int64 uint64
Floating point Half A half-precision (16-bit) floating-point number.
Single A single-precision (32-bit) floating-point number. Single float float float32 or single
Double A double-precision (64-bit) floating-point number. Double double double float or double
Logical Boolean A Boolean value (true or false). Boolean bool bool bool
Other Char A Unicode (16-bit) character. Char char wchar_t char
Decimal A decimal (128-bit) value. Decimal decimal Decimal decimal
IntPtr A signed integer whose size depends on the underlying platform (a 32-bit value on a 32-bit platform and a 64-bit value on a 64-bit platform). nint unativeint
UIntPtr An unsigned integer whose size depends on the underlying platform (a 32- bit value on a 32-bit platform and a 64-bit value on a 64-bit platform).

Not CLS-compliant.
nuint unativeint
Object The root of the object hierarchy. Object object Object^ obj
String An immutable, fixed-length string of Unicode characters. String string String^ string

In addition to the base data types, the System namespace contains over 100 classes, ranging from classes that handle exceptions to classes that deal with core runtime concepts, such as application domains and the garbage collector. The System namespace also contains many second-level namespaces.

For more information about namespaces, use the .NET API Browser to browse the .NET Class Library. The API reference documentation provides documentation on each namespace, its types, and each of their members.

Data structures

.NET includes a set of data structures that are the workhorses of many .NET apps. These are mostly collections, but also include other types.

  • Array - Represents an array of strongly typed objects that can be accessed by index. Has a fixed size, per its construction.
  • List<T> - Represents a strongly typed list of objects that can be accessed by index. Is automatically resized as needed.
  • Dictionary<TKey,TValue> - Represents a collection of values that are indexed by a key. Values can be accessed via key. Is automatically resized as needed.
  • Uri - Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.
  • DateTime - Represents an instant in time, typically expressed as a date and time of day.

Utility APIs

.NET includes a set of utility APIs that provide functionality for many important tasks.

  • HttpClient - An API for sending HTTP requests and receiving HTTP responses from a resource identified by a URI.
  • XDocument - An API for loading and querying XML documents with LINQ.
  • StreamReader - An API for reading files.
  • StreamWriter - An API for writing files.

App-model APIs

There are many app models that can be used with .NET, for example:

  • ASP.NET - A web framework for building web sites and services. Supported on Windows, Linux, and macOS (depends on ASP.NET version).
  • .NET MAUI - An app platform for building native apps that run on Windows, macOS, iOS, and Android using C#.
  • Windows Desktop - Includes Windows Presentation Foundation (WPF) and Windows Forms.

See also