http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Data_Type/Integer_Family&feed=atom&action=history
Csharp/CSharp Tutorial/Data Type/Integer Family - История изменений
2024-03-28T09:16:44Z
История изменений этой страницы в вики
MediaWiki 1.30.0
http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Data_Type/Integer_Family&diff=6228&oldid=prev
в 15:31, 26 мая 2010
2010-05-26T15:31:53Z
<p></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr style="vertical-align: top;" lang="ru">
<td colspan="1" style="background-color: white; color:black; text-align: center;">← Предыдущая</td>
<td colspan="1" style="background-color: white; color:black; text-align: center;">Версия 15:31, 26 мая 2010</td>
</tr><tr><td colspan="2" style="text-align: center;" lang="ru"><div class="mw-diff-empty">(нет различий)</div>
</td></tr></table>
http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/Data_Type/Integer_Family&diff=6229&oldid=prev
Admin: 1 версия
2010-05-26T12:18:35Z
<p>1 версия</p>
<p><b>Новая страница</b></p><div>==A C# int is a shorthand for System.Int32, which inherits the following members from System.Object==<br />
<br />
<br />
<br />
<source lang="csharp">using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
Console.WriteLine("12.GetHashCode() = {0}", 12.GetHashCode());<br />
Console.WriteLine("12.Equals(23) = {0}", 12.Equals(23));<br />
Console.WriteLine("12.ToString() = {0}", 12.ToString());<br />
Console.WriteLine("12.GetType() = {0}", 12.GetType());<br />
}<br />
}</source><br />
<br />
==Family of Integers==<br />
<br />
<p>C# defines nine integer types:</p><br />
<OL><LI>char,</LI><LI>byte,</LI><LI>sbyte,</LI><LI>short,</LI><LI>ushort,</LI><LI>int,</LI><LI>uint,</LI><LI>long,</LI><LI>ulong.</LI></OL><br />
<p>char type is used for representing characters</p><br />
<p>The integer structures are</p><br />
<OL><LI>Byte</LI><LI>SByte</LI><LI>Int16</LI><LI>UInt16</LI><LI>Int32</LI><LI>UInt32</LI><LI>Int64</LI><LI>UInt64</LI></OL><br />
<p>The integer structures also define the following const fields:</p><br />
<OL><LI>MaxValue</LI><LI>MinValue</LI></OL><br />
<p>Methods Supported by the Integer Structures</p><br />
Method<br />
Meaning<br />
public int CompareTo(object v)<br />
Returns 0 if the values are equal. Returns a negative value if the invoking object has a lower value. Returns a positive value if the invoking object has a greater value.<br />
public override bool Equals(object v)<br />
Returns true if equal.<br />
public override int GetHashCode()<br />
Returns the hash code.<br />
public TypeCode GetTypeCode()<br />
Returns the TypeCode enumeration value. For example, for Int32, the type code is TypeCode.Int32.<br />
public static retType Parse(string str)<br />
Parses the string.<br />
public static retType Parse(string str,IFormatProvider fmtpvdr)<br />
Parse string using the culture-specific information provided by fmtpvdr.<br />
public static retType Parse(string str, NumberStyles styles)<br />
Parse string using the style information provided by styles.<br />
public static retType Parse(string str, NumberStyles styles,IFormatProvider fmtpvdr)<br />
Parse string using the style information provided by styles and the culture-specific format information provided by fmtpvdr.<br />
public override string ToString()<br />
Convert value to string.<br />
public string ToString(string format)<br />
Convert value to string as specified by the format string.<br />
public stringToString(IFormatProvider fmtpvdr)<br />
Returns the string representation of the value of the invoking object using the culture-specific information.<br />
public stringToString(string format,IFormatProvider fmtpvdr)<br />
Returns the string representation of the value of the invoking object using the culture-specific information and the format.<br />
<p>All of the integer structures implement the following interfaces:</p><br />
<OL><LI>IComparable,</LI><LI>IConvertible, and</LI><LI>IFormattable.</LI></OL><br />
<br />
==Integer ranges==<br />
<br />
Type<br />
Width in Bits<br />
Range<br />
byte<br />
8<br />
0 to 255<br />
sbyte<br />
8<br />
-128 to 127<br />
short<br />
16<br />
-32,768 to 32,767<br />
ushort<br />
16<br />
0 to 65,535<br />
int<br />
32<br />
-2,147,483,648 to 2,147,483,647<br />
uint<br />
32<br />
0 to 4,294,967,295<br />
long<br />
64<br />
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807<br />
ulong<br />
64<br />
0 to 18,446,744,073,709,551,615<br />
<br />
<br />
<source lang="csharp">using System;<br />
using System.Collections.Generic;<br />
using System.Globalization;<br />
using System.IO;<br />
using System.Text;<br />
using System.Security.Cryptography;<br />
public class MainClass<br />
{<br />
public static void Main()<br />
{<br />
Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",<br />
typeof(byte).ToString(), sizeof(byte), byte.MinValue, byte.MaxValue);<br />
Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",<br />
typeof(char).ToString(), sizeof(char), (int)char.MinValue, (int)char.MaxValue);<br />
Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",<br />
typeof(short).ToString(), sizeof(short), short.MinValue, short.MaxValue);<br />
Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",<br />
typeof(int).ToString(), sizeof(int), int.MinValue, int.MaxValue);<br />
Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",<br />
typeof(long).ToString(), sizeof(long), long.MinValue, long.MaxValue);<br />
Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",<br />
typeof(sbyte).ToString(), sizeof(sbyte), sbyte.MinValue, sbyte.MaxValue);<br />
Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",<br />
typeof(ushort).ToString(), sizeof(ushort), ushort.MinValue, ushort.MaxValue);<br />
Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",<br />
typeof(uint).ToString(), sizeof(uint), uint.MinValue, uint.MaxValue);<br />
Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",<br />
typeof(ulong).ToString(), sizeof(ulong), ulong.MinValue, ulong.MaxValue);<br />
}<br />
}</source><br />
<br />
==Integer Types==<br />
<br />
<br />
<br />
<source lang="csharp">Type Size Range (Inclusive) BCL Name Signed<br />
sbyte 8 bits -128 to 127 System.SByte Yes<br />
byte 8 bits 0 to 255 System.Byte No<br />
short 16 bits -32,768 to 32,767 System.Int16 Yes<br />
ushort 16 bits 0 to 65,535 System.UInt16 No<br />
int 32 bits -2,147,483,648 to 2,147,483,647 System.Int32 Yes<br />
uint 32 bits 0 to 4,294,967,295 System.UInt32 No<br />
long 64 bits -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 System.Int64 Yes<br />
ulong 64 bits 0 to 18,446,744,073,709,551,615 System.UInt64 No</source><br />
<br />
==Use "is" for int value type==<br />
<br />
<br />
<br />
<source lang="csharp">using System;<br />
public class MainClass<br />
{<br />
static void Main() {<br />
int j = 123;<br />
object boxed = j;<br />
object obj = new Object();<br />
Console.WriteLine( "boxed {0} int", boxed is int ? "is" : "isnot" );<br />
Console.WriteLine( "obj {0} int", obj is int ? "is" : "isnot" );<br />
Console.WriteLine( "boxed {0} System.ValueType", boxed is ValueType ? "is" : "isnot" );<br />
}<br />
}</source><br />
<pre class=codeResult>boxed is int<br />
obj isnot int<br />
boxed is System.ValueType</pre></div>
Admin