In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the example analysis of C# types and C# variables, which is very detailed and has a certain reference value. Friends who are interested must finish it!
There are two types of C #: value type (value type) and reference type (reference type). Value type variables directly include their data, while reference type variables store their data references, which are considered objects. For reference types, it is possible that two variables refer to the same object, so the operation on one variable may affect the object referenced by the other object. For value types, each variable has its own copy of the data, so operations on one variable are unlikely to affect other variables (with the exception of the ref and out parameter variables).
The value type of C # is further divided into simple type (simple type), enumeration type (enum type) and structure type (struct type); the reference type of C # is further divided into class type (class type), interface type (interface type), array type (array type) and delegate type (delegate type).
Table 1.1 provides an overview of the entire C# type system.
Table 1.1 Overview of C# type systems
The eight integer types support signed or unsigned formats for 8-bit, 16-bit, 32-bit, and 64-bit integers, respectively.
Two floating-point types, float and double, are represented in 32-bit single-precision and 64-bit double-precision IEEE754 formats, respectively.
Decimal is a 128bit data type suitable for financial and monetary calculations.
The bool type of C # is used to represent a Boolean value-- true or false.
In C #, Unicode encoding is used for character and string processing. The char type represents a 16-bit Unicode encoding unit, and the string type represents a sequence of 16-bit Unicode encoding units.
Table 1.2 summarizes the numerical types of C#.
Table 1.2 numerical types of C#
The C # program uses type declarations to create new types. The type declaration specifies the name and member of the new type. There are five types of C# that can be customized by the user: class type, structure type, interface type, enumeration type, and delegate type.
The class type defines a data structure that includes data members (fields) and function members (methods, properties, and others). Class types support inheritance and polymorphism, that is, the mechanism by which derived classes can extend and specialize base classes.
Structure types are similar to class types and represent structures with data members and function members. However, unlike class types, structures are value types and do not require heap allocation. Structure does not support user-specified inheritance, and all structure types implicitly inherit the type object.
The interface type defines a convention, a collection named as a set of function members. The class or structure that implements the interface must provide an implementation of the interface function members. Interfaces may inherit from multiple base interfaces, and classes or structures may implement multiple interfaces.
Enumerated types are unique types with named constants. Each enumerated type has an underlying type, which must be one of eight integer types. The value set of the enumerated type is the same as that of the underlying type.
A delegate type represents a reference to a method through a specific parameter list and return type. The delegate treats the method as an entity, which can be assigned to a variable and passed as a parameter. Delegates are similar to method pointers in some programming languages, except that delegates are object-oriented and type-safe.
C # supports any type of one-dimensional and multidimensional arrays. Unlike other types, array types do not have to be declared before they are used. In fact, array types are constructed by a type name with parentheses above it. For example, int [] is an one-dimensional array of int, int [,] is a two-dimensional array of int, and int [] is an one-dimensional array of one-dimensional array of int.
The C # type system is unified so that values of any type can be processed into objects. Each type in C # inherits directly or indirectly from the object class, and object is the final base class for all types. Values of value types can be treated as objects by performing boxing (boxing) and unboxing (unboxing) operations. In the following example, int is converted to object and then back to int.
Using System; class Test {static void Main () {int iBox 123; object obox; / / boxed int j = (int) o; / / unboxed}}
When the value of a value type is cast to object, the object instance that holds the value (also known as the "box") is assigned and the value is copied to that box. Conversely, when an object reference is cast to a value type, check to see if the reference type is a box of the current value type, and if so, the values in the box are copied.
The C # unified type system means that value types can be converted to objects "on demand". Because of this unity, generic class libraries that use object types, such as collection classes in the .NET Framework, can be used by reference types and value types.
There are several C # variables, including fields, array elements, local variables, and parameters. Variables represent the location of storage, and each variable has a type to determine what values can be stored in the variable, as shown in Table 1.3.
Table 1.3 C # variables
The above is all the content of the article "sample Analysis of C# types and C# variables". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.