Csharp/C Sharp/Data Types/Parse — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 14:46, 26 мая 2010
bool.Parse
<source lang="csharp"> using System; using System.Collections.Generic; using System.Text; class Program {
static void Main(string[] args) { bool myBool = bool.Parse("True"); Console.WriteLine("-> Value of myBool: {0}", myBool); }
}
</source>
char.Parse
<source lang="csharp"> using System; using System.Collections.Generic; using System.Text; class Program {
static void Main(string[] args) { char myChar = char.Parse("w"); Console.WriteLine("-> Value of myChar: {0}\n", myChar); }
}
</source>
double.Parse
<source lang="csharp"> using System; using System.Collections.Generic; using System.Text; class Program {
static void Main(string[] args) { double myDbl = double.Parse("99.884"); Console.WriteLine("-> Value of myDbl: {0}", myDbl); }
}
</source>
int.Parse
<source lang="csharp"> using System; using System.Collections.Generic; using System.Text; class Program {
static void Main(string[] args) { int myInt = int.Parse("8"); Console.WriteLine("-> Value of myInt: {0}", myInt); }
}
</source>
parse decimal
<source lang="csharp"> using System; public class Class1 {
public static void Main(string[] args) { Console.Write("Enter principal:"); string sPrincipal = Console.ReadLine(); decimal mPrincipal = decimal.Parse(sPrincipal); Console.Write("Enter interest:"); string sInterest = Console.ReadLine(); decimal mInterest = decimal.Parse(sInterest); decimal mInterestPaid; mInterestPaid = mPrincipal * (mInterest / 100); decimal mTotal = mPrincipal + mInterestPaid; Console.WriteLine("Principal = " + mPrincipal); Console.WriteLine("Interest = " + mInterest + "%"); Console.WriteLine("Interest paid = " + mInterestPaid); Console.WriteLine("Total = " + mTotal); }
}
</source>