System
, itself.
The Members of System
In addition to a large number of exception classes,
System
contains the following classes:
ActivationContext Activator
AppDomain
AppDomainManager AppDomainSetup
ApplicationId
ApplicationIdentity Array
AssemblyLoadEventArgs
Attribute
AttributeUsageAttribute
BitConver ter
Buffer
CharEnumerator
CLSCompliantAttribute
Console
ConsoleCancelEventArgs ContextBoundObject
ContextStaticAttribute
Conver t
DBNull
Delegate
Enum
Environment
EventArgs
Exception
FileStyleUriParser
FlagsAttribute
FtpStyleUriParser GC
GenericUriParser GopherStyleUriParser
HttpStyleUriParser
LdapStyleUriParser LoaderOptimizationAttribute
LocalDataStoreSlot
MarshalByRefObject
Math
MTAThreadAttribute
MulticastDelegate
NetPipeStyleUriParser NetTcpStyleUriParser
615
CHAPTER
www.freepdf-books.com
616
P a r t I I :
E x p l o r i n g t h e C # L i b r a r y
NewsStyleUriParser NonSerializedAttribute
Nullable
Object
ObsoleteAttribute
OperatingSystem
ParamArrayAttribute
Random
ResolveEventArgs
SerializableAttribute
STAThreadAttribute
String
StringComparer
ThreadStaticAttribute
TimeZone
TimeZoneInfo TimeZoneInfo.AdjustmentRule
Type
UnhandledExceptionEventArgs
Uri
UriBuilder
UriParser
UriTemplate UriTemplateEquivalenceComparer
UriTemplateTable UriTypeConver ter ValueType
Version
WeakReference
System
defines the following structures:
ArgIterator
ArraySegment Boolean
Byte
Char
ConsoleKeyInfo
DateTime
DateTimeOffset
Decimal
Double
Guid
Int16
Int32
Int64
IntPtr
ModuleHandle
Nullable RuntimeArgumentHandle
RuntimeFieldHandle
RuntimeMethodHandle
RuntimeTypeHandle
Sbyte
Single
TimeSpan
TimeZoneInfo.TransitionTime TypedReference
UInt16
UInt32
UInt64
UIntPtr
Void
System
defines the following interfaces:
_AppDomain
IAppDomainSetup
IAsyncResult
ICloneable
IComparable
IComparable
IConver tible ICustomFormatter
IDisposable
IEquatable IFormatProvider
IFormattable
ISer viceProvider
www.freepdf-books.com
PART II
C h a p t e r 2 1 :
E x p l o r i n g t h e S y s t e m N a m e s p a c e
617
System
defines the following delegates:
Action
Action Action
T2>
Action
Action
AppDomainInitializer
AssemblyLoadEventHandler
AsyncCallback
Comparison
ConsoleCancelEventHandler
Conver ter
CrossAppDomainDelegate
EventHandler
EventHandler Func
Func
Func
Func
Func
Predicate
ResolveEventHandler
UnhandledExceptionEventHandler
System
defines these enumerations:
ActivationContext.contextForm AppDomainManagerInitializationOptions AttributeTargets
Base64FormattingOptions ConsoleColor
ConsoleKey
ConsoleModifiers
ConsoleSpecialKey
DateTimeKind
DayOfWeek
Environment.SpecialFolder
EnvironmentVariableTarget
GCCollectionMode
GenericUriParserOptions
LoaderOptimization
MidpointRounding
PlatformID
StringComparison
StringSplitOptions TypeCode
UriComponents
UriFormat UriHostNameType
UriIdnScope
UriKind UriPar tial
As the preceding tables show,
System
is quite large. It is not possible to examine all of
its constituents in detail in a single chapter. Furthermore, several of
System
’s members, such
as
Nullable
,
Type
,
Exception
, and
Attribute
, are discussed in Part I or elsewhere in
Part II. Finally, because
System
.
String
, which defines the C#
string
type, is such a large and
important topic, it is covered in Chapter 22 along with formatting. For these reasons, this
chapter explores only those members that are most commonly used by C# programmers
and that are not fully covered elsewhere.
The Math Class
Math
defines several standard mathematical operations, such as square root, sine, cosine,
and logarithms. The
Math
class is
static
, which means all of the methods defined by
Math
are
static
and no object of type
Math
can be constructed. It also means
Math
is implicitly
sealed and cannot be inherited. The methods defined by
Math
are shown in Table 21-1. All
angles are in radians.
Math
also defines these two fields:
public const double E
public const double PI
www.freepdf-books.com
618
P a r t I I :
E x p l o r i n g t h e C # L i b r a r y
E
is the value of the natural logarithm base, commonly referred to as
e.
PI
is the value of pi.
Method
Meaning
public static double Abs(double
v
)
Returns the absolute value of
v.
public static float Abs(float
v
)
Returns the absolute value of
v.
public static decimal Abs(decimal
v
)
Returns the absolute value of
v.
public static int Abs(int
v
)
Returns the absolute value of
v.
public static shor t Abs(shor t
v
)
Returns the absolute value of
v.
public static long Abs(long
v
)
Returns the absolute value of
v.
public static sbyte Abs(sbyte
v
)
Returns the absolute value of
v.
public static double Acos(double
v
)
Returns the arc cosine of
v.
The value of
v
must be
between –1 and 1.
public static double Asin(double
v
)
Returns the arc sine of
v.
The value of
v
must be
between –1 and 1.
public static double Atan(double
v
)
Returns the arc tangent of
v.
public static double Atan2(double
y
,
double
x
)
Returns the arc tangent of
y
/
x.
public static long BigMul(int
x
, int
y
)
Returns the result of
x
*
y
as a
long
value, thus
avoiding over flow.
public static double Ceiling(double
v
)
Returns the smallest integer (represented as a
floating-point value) not less than
v.
For example,
given 1.02,
Ceiling( )
returns 2.0. Given –1.02,
Ceiling( )
returns –1.
public static double Ceiling(decimal
v
)
Returns the smallest integer (represented as a
decimal value) not less than
v.
For example, given
1.02,
Ceiling( )
returns 2.0. Given –1.02,
Ceiling( )
returns –1.
public static double Cos(double
v
)
Returns the cosine of
v.
public static double Cosh(double
v
)
Returns the hyperbolic cosine of
v.
public static int DivRem(int
x
, int
y
,
out int
rem
)
Return the result of
x
/
y.
The remainder is returned
in
rem.
public static long DivRem(long
x
, long
y
,
out long
rem
)
Return the result of
x
/
y.
The remainder is returned
in
rem.
public static double Exp(double
v
)
Returns the natural logarithm base
e
raised to the
v
power.
public static decimal Floor(decimal
v
)
Returns the largest integer (represented as a decimal
value) not greater than
v.
For example, given 1.02,
Floor( )
returns 1.0. Given –1.02,
Floor( )
returns –2.
T
ABLE
21-1
Methods Defi ned by
Math
www.freepdf-books.com
PART II
C h a p t e r 2 1 :
E x p l o r i n g t h e S y s t e m N a m e s p a c e
619
public static double Floor(double
v
)
Returns the largest integer (represented as a floating-
point value) not greater than
v.
For example, given
1.02,
Floor( )
returns 1.0. Given –1.02,
Floor( )
returns –2.
public static double
IEEERemainder(double
dividend
,
double
divisor
)
Returns the remainder of
dividend
/
divisor.
public static double Log(double
v
)
Returns the natural logarithm for
v.
public static double Log(double
v
,
double
base
)
Returns the logarithm for
v
using base
base.
public static double Log10(double
v
)
Returns the base 10 logarithm for
v.
public static double Max(double
v1
,
double
v2
)
Returns the greater of
v1
and
v2.
public static float Max(float
v1,
float
v2
)
Returns the greater of
v1
and
v2.
public static decimal Max(decimal
v1
,
decimal
v2
)
Returns the greater of
v1
and
v2.
public static int Max(int
v1
, int
v2
)
Returns the greater of
v1
and
v2.
public static shor t Max(shor t
v1
, shor t
v2
)
Returns the greater of
v1
and
v2.
public static long Max(long
v1
, long
v2
)
Returns the greater of
v1
and
v2.
public static uint Max(uint
v1
, uint
v2
)
Returns the greater of
v1
and
v2.
public static ushor t Max(ushor t
v1
,
ushor t
v2
)
Returns the greater of
v1
and
v2.
public static ulong Max(ulong
v1
,
ulong
v2
)
Returns the greater of
v1
and
v2.
public static byte Max(byte
v1
, byte
v2
)
Returns the greater of
v1
and
v2.
public static sbyte Max(sbyte
v1
, sbyte
v2
)
Returns the greater of
v1
and
v2.
public static double Min(double
v1
,
double
v2
)
Returns the lesser of
v1
and
v2.
public static float Min(float
v1
, float
v2
)
Returns the lesser of
v1
and
v2.
public static decimal Min(decimal
v1
,
decimal
v2
)
Returns the lesser of
v1
and
v2.
public static int Min(int
v1
, int
v2
)
Returns the lesser of
v1
and
v2.
public static shor t Min(shor t
v1
, shor t
v2
)
Returns the lesser of
v1
and
v2.
public static long Min(long
v1
, long
v2
)
Returns the lesser of
v1
and
v2.
public static uint Min(uint
v1
, uint
v2
)
Returns the lesser of
v1
and
v2.
public static ushor t Min(ushor t
v1
,
ushor t
v2
)
Returns the lesser of
v1
and
v2.
T
ABLE
21-1
Methods Defi ned by
Math
(continued)
Method
Meaning
www.freepdf-books.com
620
P a r t I I :
E x p l o r i n g t h e C # L i b r a r y
public static ulong Min(ulong
v1
, ulong
v2
)
Returns the lesser of
v1
and
v2.
public static byte Min(byte
v1
, byte
v2
)
Returns the lesser of
v1
and
v2.
public static sbyte Min(sbyte
v1
, sbyte
v2
)
Returns the lesser of
v1
and
v2.
public static double Pow(double
base
,
double
exp
)
Returns
base
raised to the
exp
power(
base
exp
).
public static double Round(double
v
)
Returns
v
rounded to the nearest whole number.
public static decimal Round(decimal
v
)
Returns
v
rounded to the nearest whole number.
public static double Round(double
v
,
int
frac
)
Returns
v
rounded to the number of fractional digits
specified by
frac.
public static decimal Round(decimal
v
,
int
frac
)
Returns
v
rounded to the number of fractional digits
specified by
frac.
public static double Round(double
v
,
MidpointRounding
how
)
Returns
v
rounded to the nearest whole number using
the rounding mode specified by
how.
public static decimal Round(decimal
v
,
MidpointRounding
how
)
Returns
v
rounded to the nearest whole number using
the rounding mode specified by
how.
public static double Round(double
v
,
int
frac
,
MidpointRounding
how
)
Returns
v
rounded to the number of fractional digits
specified by
frac.
It uses the rounding mode specified
by
how.
public static decimal Round(decimal
v
,
int
frac
,
MidpointRounding
how
)
Returns
v
rounded to the number of fractional digits
specified by
frac.
It uses the rounding mode specified
by
how.
public static int Sign(double
v
)
Returns –1 if
v
is less than zero, 0 if
v
is zero, and
1 if
v
is greater than zero.
public static int Sign(float
v
)
Returns –1 if
v
is less than zero, 0 if
v
is zero, and
1 if
v
is greater than zero.
public static int Sign(decimal
v
)
Returns –1 if
v
is less than zero, 0 if
v
is zero, and
1 if
v
is greater than zero.
public static int Sign(int
v
)
Returns –1 if
v
is less than zero, 0 if
v
is zero, and
1 if
v
is greater than zero.
public static int Sign(shor t
v
)
Returns –1 if
v
is less than zero, 0 if
v
is zero, and
1 if
v
is greater than zero.
public static int Sign(long
v
)
Returns –1 if
v
is less than zero, 0 if
v
is zero, and
1 if
v
is greater than zero.
public static int Sign(sbyte
v
)
Returns –1 if
v
is less than zero, 0 if
v
is zero, and
1 if
v
is greater than zero.
public static double Sin(double
v
)
Returns the sine of
v.
public static double Sinh(double
v
)
Returns the hyperbolic sine of
v.
Method
Meaning
T
ABLE
21-1
Methods Defi ned by
Math
(continued)
www.freepdf-books.com
Do'stlaringiz bilan baham: |