Csharp/C Sharp by API/System/Int32

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Int32.Equals(23)

<source lang="csharp"> using System; using System.Collections.Generic; using System.Text; class Program {

   static void Main(string[] args) {
       Console.WriteLine(12.GetHashCode());
       Console.WriteLine(12.Equals(23));
       Console.WriteLine(12.GetType().BaseType);
       Console.WriteLine(12.ToString());
       Console.WriteLine(12); // ToString() called automatically.
   }

}

 </source>


Int32.GetHashCode

<source lang="csharp"> using System; using System.Collections.Generic; using System.Text; class Program {

   static void Main(string[] args) {
       Console.WriteLine(12.GetHashCode());
       Console.WriteLine(12.Equals(23));
       Console.WriteLine(12.GetType().BaseType);
       Console.WriteLine(12.ToString());
       Console.WriteLine(12); // ToString() called automatically.
   }

}

 </source>


Int32.GetType()

<source lang="csharp"> using System; using System.Reflection;

class TypeObjectFromInstanceApp {

   public static void Main(string[] args)
   {
       int i = 6;
       Type type = i.GetType();
       Console.WriteLine(type.Name);
   }

}


 </source>


Int32 == Int32

<source lang="csharp">


using System; class MainClass {

   public static void Main(string[] args)
   {
   System.Int32 intA = 1001;
   System.Int32 intB = 1000;
   
   if(intA == intB)
     Console.WriteLine("Same value!\n");
   else
     Console.WriteLine("Not the same value!\n");
   }

}


 </source>


Int32.Parse(String value)

<source lang="csharp"> using System; class MainClass {

   public static void Main(string[] args)
   {
   int myInt = int.Parse("8");
   Console.WriteLine("-> Value of myInt: {0}", myInt);
   }

}


 </source>


Int32.ToString

<source lang="csharp"> using System; using System.Collections.Generic; using System.Text; class Program {

   static void Main(string[] args) {
       Console.WriteLine(12.GetHashCode());
       Console.WriteLine(12.Equals(23));
       Console.WriteLine(12.GetType().BaseType);
       Console.WriteLine(12.ToString());
       Console.WriteLine(12); // ToString() called automatically.
   }

}

 </source>


Int32.ToString(String format,CultureInfo info)

<source lang="csharp">

using System; using System.Globalization; using System.Threading; class Program {

   static void Main(string[] args) {
       int val = 1234567890;
       Console.WriteLine(val.ToString("N"));
       Console.WriteLine(val.ToString("N",new CultureInfo("fr-FR")));
       Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
       Console.WriteLine(val.ToString("N"));
   }

}


 </source>


UInt32.MinValue

<source lang="csharp"> using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; using System.Security.Cryptography; public class MainClass {

   public static void Main()
   {
       Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",
           typeof(byte).ToString(), sizeof(byte), byte.MinValue, byte.MaxValue);
       Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",
           typeof(char).ToString(), sizeof(char), (int)char.MinValue, (int)char.MaxValue);
       Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",
           typeof(short).ToString(), sizeof(short), short.MinValue, short.MaxValue);
       Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",
           typeof(int).ToString(), sizeof(int), int.MinValue, int.MaxValue);
       Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",
           typeof(long).ToString(), sizeof(long), long.MinValue, long.MaxValue);
       Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",
           typeof(sbyte).ToString(), sizeof(sbyte), sbyte.MinValue, sbyte.MaxValue);
       Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",
           typeof(ushort).ToString(), sizeof(ushort), ushort.MinValue, ushort.MaxValue);
       Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",
           typeof(uint).ToString(), sizeof(uint), uint.MinValue, uint.MaxValue);
       Console.WriteLine("{0}: bytes: {1}, range: [{2},{3}]",
           typeof(ulong).ToString(), sizeof(ulong), ulong.MinValue, ulong.MaxValue);
   }

}


 </source>