11.1.3 Simple types

11.1.3 Simple types
C# provides a set of predefined struct types called the simple types. The
simple types are identified through
reserved words, but these reserved words are simply aliases for predefined
struct types in the System
namespace, as described in the table below.
Reserved word Aliased type
sbyte System.SByte
byte System.Byte
short System.Int16
ushort System.UInt16
int System.Int32
uint System.UInt32
long System.Int64
ulong System.UInt64
char System.Char
float System.Single
double System.Double
bool System.Boolean
decimal System.Decimal
Because a simple type aliases a struct type, every simple type has members.
[Example: For example, int
has the members declared in System.Int32 and the members inherited from
System.Object, and the
following statements are permitted:
int i = int.MaxValue; // System.Int32.MaxValue constant
string s = i.ToString(); // System.Int32.ToString() instance method
string t = 123.ToString(); // System.Int32.ToString() instance method
end example] The simple types differ from other struct types in that they
permit certain additional
operations:
?Most simple types permit values to be created by writing literals (?.4.4).
[Example: For example, 123
is a literal of type int and 抋?is a literal of type char. end example] C#
makes no provision for literals
of struct types in general, and non-default values of other struct types
are ultimately always created
through instance constructors of those struct types.
?When the operands of an expression are all simple type constants, the
compiler evaluates the expression
at compile-time. Such an expression is known as a constant-expression (?4.15
). Expressions involving
operators defined by other struct types are not considered to be constant
expressions.
?Through const declarations, it is possible to declare constants of the
simple types (?7.3). It is not
possible to have constants of other struct types, but a similar effect is
provided by static readonly
fields.
?Conversions involving simple types can participate in evaluation of
conversion operators defined by
other struct types, but a user-defined conversion operator can never
participate in evaluation of another
user-defined operator (?3.4.2).
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值